Issue 1:
Feature request

Request to add the documentation on how to add routes dynamically in Router array in server.js or any other appropriate place when an API call can be made.

I would like to avoid custom server and stay with Next.js defaults.

Is your feature request related to a problem? Please describe.

I have some urls like following.

http://ww.example.com/something/ -> somePage.js
http://ww.example.com/something/hello/hi -> somePage.js
http://ww.example.com/xyz/hello/hi -> somePage.js
http://ww.example.com/abc/hello/hi -> otherPage.js
http://ww.example.com/abc/dfg -> otherPage.js
http://ww.example.com/water -> otherPage.js
http://ww.example.com/toys -> anyPage.js

The issue is that none of the URLs have any info about the Page that they need to map to. Also they don't follow any pattern.

All the example I found have page info in the url like this /post/[id] or /post/postName, so it becomes easier to identify the page the url map to but in my case page info or any other hint is not there.

Describe the solution you'd like

I want to add the above url mappings that can go to any number in future but at present I have something like 300 urls.

I would like to add all urls as routes to page mappings in routes array, as shown in pic.

I found the following code in Next.js source code:

/// <reference types="node" />
import { IncomingMessage, ServerResponse } from 'http';
import { UrlWithParsedQuery } from 'url';
export declare const route: (path: string) => (pathname: string | undefined, params?: any) => any;
export declare type Params = {
[param: string]: any;
};
export declare type RouteMatch = (pathname: string | undefined) => false | Params;
export declare type Route = {
match: RouteMatch;
fn: (req: IncomingMessage, res: ServerResponse, params: Params, parsedUrl: UrlWithParsedQuery) => void;
};
export default class Router {
routes: Route[];
constructor(routes?: Route[]);
add(route: Route): void;
match(req: IncomingMessage, res: ServerResponse, parsedUrl: UrlWithParsedQuery): (() => void) | undefined;
}

This code declares Route but I am not sure how do I create a new Route and add it to routes array so routing happens automatically.

I would like to add all the routes to routes array at the server start-up and update them after a set interval.

Describe alternatives you've considered

At present I have something like following working, on server side:

app.prepare().then(() => {
createServer((req, res) => {
// Be sure to pass `true` as the second argument to `url.parse`.
// This tells it to parse the query portion of the URL.
const parsedUrl = parse(req.url, true);
const { pathname, query } = parsedUrl;
if (urlMappings.includes(pathname)) {
// the path value should be externalized later.
// So mappings can changed without redeploying the app.
//Current pathname passed as query param to mypage.
app.render(req, res, '/mypage', { ...query, newQueryParam: pathname });
} else {
handle(req, res, parsedUrl);
}
}).listen(port, err => {
if (err) throw err;
console.log(`> Ready on http://localhost:${port}`);
});
});

The problem with this approach is that I have to maintain large array and do if-else in server.js.

Also the routes can not be updated if new pages are added to URL array.

if (urlMappings.includes(pathname)) {

On Client Side I am able to utilize Link component as feature to change the displayed link in browser.

Other approach I am thinking of is to make an api call in server.js to get url to page mapping but thats expensive as it added some time to each request.

Additional context

Is there any way to ask Next.js that if this url maps to any of its page, if it maps I will let Next.js handle the request, else I can check in url array and do custom mappings to page, so I dont check url array for all valid requests that map to pages directly ?

I asked similar question on stackoverflow and Spectrum but have not received any response. So this is my last place to ask for help. I am new to JS or TS, still building the understanding on how they work. Thanks in advance.

Issue 2:
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.