PenguinScola
PenguinScola

Reputation: 31

How to handle % and # characters with next-routes

I am using next-routes and my application URL need to receive parameter as name that contains % and # characters. For example, "C#", "100%" etc.

So its URL will look like below.

  1. https://myapp.com/name/C#
  2. https://myapp.com/name/100%
  3. https://myapp.com/name/harry_potter

For "C#", I have found that query value from the 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.

https://user-images.githubusercontent.com/18202926/48536863-659f6d00-e8e2-11e8-8c64-a0180b51e921.png

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

NB. I opened the issue on next-routes here

Upvotes: 3

Views: 3877

Answers (1)

Dhananjai Pai
Dhananjai Pai

Reputation: 6005

You will have to encode the URI component so that the special characters are not used.

if you must get C# it would be encoded as "C%23" 100% would be "100%25" and so forth.

use the encodeURIComponent() function to generate the appropriate URI.

Hope it helps. refer if needed : escaping special character in a url

Upvotes: 1

Related Questions