vercel / next.js

The React Framework
https://nextjs.org
MIT License
127.06k stars 27k forks source link

paths get url-encoded with next export and getStaticPaths #11016

Open meesvandongen opened 4 years ago

meesvandongen commented 4 years ago

Bug report

Describe the bug

Paths get url-encoded when using next export. This causes them to get double-encoded when live.

To Reproduce

test case: https://gitlab.com/meesvandongen/test-case-next-export

build & export the project, serve it and go to the relevant page:

Expected behavior

The routes are exported without encoding.

Additional context

This behaviour is different from exportPathMap, where the behaviour was as desired.

machineghost commented 3 years ago

This bug is nearly a year old; if it's not going to get fixed, at the very least could someone please add some documentation saying "you can't URI encode in getStaticPaths"?

BURROO commented 2 years ago

Has there been some development on this? I am struggling to get a readable search, filter and sort query due to this issue. Is there another work around to include characters like a ',' or '+' in a query string?

machineghost commented 2 years ago

It's been over a year ... and still no one has added even a single sentence anywhere in the documentation saying anything to the effect of "Next.js routes, whether dynamic or not, can't have % characters in them." (or "can't be URI Encoded", or whatever the actual details are).

C'mon Next team: why do you hate new users of your framework so much that you can't explain how it works to them with one line of documentation? It would literally take you < 10 minutes to make the PR for this.

P.S. I would happily submit the PR myself, if I knew what the Next rules on encoding special characters in URLs actually were.

thanhtutzaw commented 2 years ago

Also cannot decode url ( %20 ) in next/link . Any Idea ? Example url thor route works url the%20avengers route didn't work but path is already generated with the-avengers route so I can access with manual typing in url bar not from Link

saurabhck12 commented 1 year ago

This bug is nearly a year old; if it's not going to get fixed, at the very least could someone please add some documentation saying "you can't URI encode in getStaticPaths"?

What would be the workaround to this?

muzucode commented 1 year ago

Ran into this issue when creating static paths based off of a set of blog post titles from my Strapi CMS.

Very frustrating. The paths without URI encoding (but still valid paths, such as /coffee) worked. Any paths that were URI encoded (containing %s), did not work. Do I have to devise a replacement strategy (ie. replace all URI-unfriendly characters with non-%s) and then undo that, and query for the correct post when in getStaticProps()?

What's the fix???

iShelar commented 1 year ago

@muzucode Where are you going host this static site?

muzucode commented 1 year ago

@iShelar The site is currently hosted on an EC2 instance. But I am planning to move it to Digital Ocean.

Edit: I should also mention it is not a static site. There are some static paths, but the bulk of the site is backed by Strapi CMS. The statically generated pages are created from dynamically querying all the posts in my DB that's wired up with Strapi.

meesvandongen commented 1 year ago

Ran into this issue when creating static paths based off of a set of blog post titles from my Strapi CMS.

Very frustrating. The paths without URI encoding (but still valid paths, such as /coffee) worked. Any paths that were URI encoded (containing %s), did not work. Do I have to devise a replacement strategy (ie. replace all URI-unfriendly characters with non-%s) and then undo that, and query for the correct post when in getStaticProps()?

What's the fix???

Fwiw, this is exactly what I did.

iShelar commented 1 year ago

Ran into this issue when creating static paths based off of a set of blog post titles from my Strapi CMS. Very frustrating. The paths without URI encoding (but still valid paths, such as /coffee) worked. Any paths that were URI encoded (containing %s), did not work. Do I have to devise a replacement strategy (ie. replace all URI-unfriendly characters with non-%s) and then undo that, and query for the correct post when in getStaticProps()? What's the fix???

Fwiw, this is exactly what I did.

You can make regex to allow only characters that are supported by getstaticpaths. This can be a workaround.

smyja commented 1 year ago

over 3 years now.