question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

decouple route path from filename

See original GitHub issue

Feature 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:closed
  • Created 4 years ago
  • Reactions:40
  • Comments:13 (7 by maintainers)

github_iconTop GitHub Comments

11reactions
timneutkenscommented, Sep 8, 2019

A different RFC will be posted soon.

9reactions
isaachinmancommented, Aug 21, 2019

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

How and why did modern web application frameworks evolve ...
I am most familiar with PHP frameworks and many popular modern frameworks use this decoupled routing approach. To make it work you set...
Read more >
JS: Most optimized way to remove a filename from a path in a ...
Use lastIndexOf() to find the position of the last slash and get the part before the slash with substring(). str.substring(0, str.
Read more >
Node.js fs.unlink() Method - GeeksforGeeks
The fs.unlink() method is used to remove a file or symbolic link from the filesystem. This function does not work on directories, therefore...
Read more >
pathinfo - Manual - PHP
pathinfo() returns information about path : either an associative array or ... with my own written functions, I would first split path from...
Read more >
path.normalize(p) : nodejs API
This module contains utilities for handling and transforming file paths. Almost all these methods perform only string transformations. The file system is not ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found