Optional parameters
See original GitHub issueHi,
I currently have a route structure that looks like this:
- Main (all routes) – Home (/:continent?) – Entity (/:country/:region/:city)
The continent path is optional. How can I achieve this with Router5? The only requirement that I have is that both /
and /africa
(for instance) have the same parent (Home
) route. I’ve tried fiddling with absolute paths, and regexes with empty strings, but all approaches break down at some point.
Issue Analytics
- State:
- Created 6 years ago
- Comments:16 (7 by maintainers)
Top Results From Across the Web
Named and Optional Arguments - C# Programming Guide
Named arguments enable you to specify an argument for a parameter by matching the argument with its name rather than with its position...
Read more >C# | Optional Parameters - GeeksforGeeks
The optional parameters are always defined at the end of the parameter list. Or in other words, the last parameter of the method,...
Read more >What is an Optional parameter in C#? - Tutorialspoint
It means we call method without passing the arguments. The optional parameter contains a default value in function definition. If we do not...
Read more >Optional Parameters in Java: Common Strategies and ...
Learn how to structure your code and build objects with a large number of optional parameters, in a readable and well-structured manner.
Read more >Declaring optional function parameters in JavaScript - Flexiple
By definition, an Optional Parameter is a handy feature that enables programmers to pass less number of parameters to a function and assign...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Optional parameters are not supported in router5 (a design decision), and the way to achieve it is to define two routes (one with param, one without) with a parent forwarding to the non-param one by default (using
forwardTo
route option).Don’t forget to set router5 option
useTrailingSlash: false
for it to strip trailing slashes when building (or set it totrue
if you want trailing slashes to always be added).In your case, something like:
Now I see, didn’t notice that in changelog, thanks! But seems it doesn’t work in that case
I have
And if I navigate to
/ip/5
I getUncaught Error: Cannot build path: '/:version' requires missing parameters { version } at Path.build$$1