next-routes icon indicating copy to clipboard operation
next-routes copied to clipboard

How to handle % and # characters on parameter

Open PenguinScola opened this issue 5 years ago • 3 comments

I am developing tag tracking system on NextJS and my application URL need to receive parameter as tag name that contains % and # characters. For example, "C#", "100%" etc.

So its URL will look like below.

https://myapp.com/tag/C# https://myapp.com/tag/100% https://myapp.com/tag/harry_potter

For "C#", I have found that query value from getInitialProps function will be "C" only (# character is cut) and for "100%", I have found that next-routes return error as below. URI malformed has occurred on decodeURIComponent function because of % character.

image

If I need to handle both of characters, could you please suggest how can I handle them by using next-routes?

PenguinScola avatar Nov 15 '18 07:11 PenguinScola

I'm having the same question as @PenguinScola.

karolisgrinkevicius avatar Dec 04 '18 13:12 karolisgrinkevicius

Any solution to this issue, I'm also having this problem :(

nagibmahfuj avatar Nov 30 '19 10:11 nagibmahfuj

Lastly I did this to resolve on my server.js file.

const server = express();
server.use(function(req, res, next) {
    try {
        decodeURIComponent(req.originalUrl);
    } catch (err) {
        res.redirect(301, "/");
        next(err);
    }
});
// Do other stuffs
server.use(handler).listen(3000);

nagibmahfuj avatar Dec 03 '19 18:12 nagibmahfuj