fridays / next-routes

Universal dynamic routes for Next.js
MIT License
2.47k stars 230 forks source link

How to handle % and # characters on parameter #256

Closed PenguinScola closed 1 year ago

PenguinScola commented 5 years ago

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?

karolisgrinkevicius commented 5 years ago

I'm having the same question as @PenguinScola.

nagibmahfuj commented 4 years ago

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

nagibmahfuj commented 4 years ago

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);