decouple route path from filename
See original GitHub issueFeature request
Is your feature request related to a problem? Please describe.
url structures are still visible on devices, so its a UI-element and often is bound to editorial decisions, yet in nextjs, url routes always reflect the filesystem of the project
Having the filename of a page be the route path segment might be ok, if you develop for an english target group, but leads to problems in other markets. E.g. in switzerland we often need to have an app in multiple languages and customers often wish that the url paths are also translated.
Also, there is a common practice, that source code is always in english. So this leads to the problem, that when you decide to have e.g. german url paths, you need to have german-named files in your app, which just feels wrong.
Nextjs should therefore provide a firstclass support to translate url path segments.
Describe the solution you’d like
There should be a way to provide aliases to pages in code. So a page would be delivered on all available aliases. It should be possible to use translation services to provide these aliases. They should work both on server and on client.
If you use a <Link />
to a page, you can provide some context, so that nextjs would use the right alias to make the route. E.g. you could provide the locale.
I don’t know nextjs good enough to suggest an api for it yet, but suggestions are very welcome!
Describe alternatives you’ve considered
Doing it with dynamic routes (next 9 feature), is nearly impossible, because every page and folder would basically look like [slug].js
, so you would need to deliver the right page yourself, defeating the purpose of the whole file-system-routing.
It’s only possible with a custom server and some boilerplate, so that your <Link />
behave correctly. But this is needs careful setup, so that you don’t have duplicated route declarations and it is therefore error-prone.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:40
- Comments:13 (7 by maintainers)
Top GitHub Comments
A different RFC will be posted soon.
Want to chime in by saying that downstream dependencies like
next-i18next
need to be able to insert subpaths without making modifications to the filesystem.Functionality which previously worked in NextJs v8 is now broken in v9.
See https://github.com/isaachinman/next-i18next/issues/413.
If the core team is happy with merging a fix for this, and can point me in the right direction, I can get a PR through. Thanks!