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.

Dynamic routing with prefix

See original GitHub issue

Feature request

we have a problem where we want to keep almost everything at the top level while support different dynamic routes with constant prefixes as differentiator. For example we have one route example.com/@username where @ is a constant prefix and also another route example.com/[123_post_id] where the prefix is 123_... but [@username].tsxis not different from[123_post_id].tsx`

I understand we can put them into different folders and manage but the above is just an example and our application behaviour is based on prefixes and everything being at the top level

Describe the solution you’d like

Ideally ability to add some sort of prefix to dynamic routing file names. i.e. [@:username] where @ is a prefix and username is the parameter … another design solution might be [<@>username] or [username<@>] where @ is a required fixed constant but can be placed anywhere [far more complex in implementation than prefixes]

Describe alternatives you’ve considered

  • For now the native solution of /profile/[username]/... seems like the only option
  • Introducing a route manager to handle this situation
  • reverse proxy

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bamzicommented, Sep 17, 2020

This issue / feature request needs to be reopened. It was prematurely closed without addressing the actual request.

“rewrite” function DOES NOT work to address the request. Please read more carefully before jumping into conclusion.

rewrite rule barely works with code below: example.com/@username

The following case doesn’t work: example.com/@username/about <- 404 not found but this works: example.com/u/:username/about

*** If the above case “should work” but it’s not, then that’s a bug that needs to be addressed

module.exports = {
	async rewrites() {
		return [
			{
			       // The only things that works but not what we want!!!
			       // example.com/@username/about <-- 404 not found
				source: '/@:username',
				destination: '/u/:username',
			},
			// BUT none of these work:
			//{
			//	source: '/@:username*',
			//	destination: '/u/:username*',
			//  --> `example.com/@username/about` <- 404 not found
			//},
			// {
			// 	source: '/@:username((?!.*\\.\\.)(?!.*\\.$)[^\\W][\\w.]{0,29})*', <- 404 not found
			// 	destination: '/u/:username*',
			// },
			// {
			// 	source: '/@:username((?!.*\\.\\.)(?!.*\\.$)[^\\W][\\w.]{0,29})', <- top level only, not child pages
			// 	destination: '/u/:username*',
			        // example.com/@username/about <-- 404 not found
			// },
			// {
			// 	source: '/:username(@(?!.*\\.\\.)(?!.*\\.$)[^\\W][\\w.]{0,29})*', <- top level only but not child pages
			// 	destination: '/u/:username*',
			       // example.com/@username/about <-- 404 not found
			// },
		];
	},
};
0reactions
balazsorban44commented, Feb 11, 2022

This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic Routing Prefix Lists | TNSR Documentation
To create a new prefix list, use the route dynamic prefix-list <name> command, which enters config-prefix-list mode:.
Read more >
How to set dynamic route prefix in Laravel? - Stack Overflow
I need to create an app with multiple locales. And each route is prefixed with the locale. For example, xxx.com/en/home , xxx.com/fr/home ....
Read more >
Dynamic prefix routing - Laracasts
In the app/Http/Middleware/Authenticate class, this route is returned when not authenticated. You can see this in action if you change the order of...
Read more >
prefix (Dynamic Router Advertisement) | Junos OS
prefix —Prefix name. For dynamic configuration, specify the $junos-ipv6–ndra-prefix dynamic variable. The remaining statements are explained separately.
Read more >
Cloud Router overview - Google Cloud
The dynamic routing mode also controls how each Cloud Router applies learned prefixes as custom dynamic routes in a VPC network. For details...
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