Closed AhmadMayo closed 6 years ago
You can use named param:
const route = {
path: ':any(.*)',
action: (context) => {
console.log(context.params); // => { any: '/' }
}
}
Demo: https://jsfiddle.net/b0w9mjck/114/
What the expected behavior you want to achieve?
no params at all. I don't want the router to treat url segments as params, I want him to treat the whole url as 'not found' or 'other'
Have you tried to use regexp path: /.*/,
? https://jsfiddle.net/b0w9mjck/118/
works like a charm. Thank you.
This should be mentioned in the read me
I'm submitting a ...
Routes definition:
Going to the route / -which I don't have a defined route for - will log this to the console
{0: '/'}
The problem is that defining the path as(.*)
will create an unnamed parameter with the value '/', and defining the path like this/(.*)
will create an unnamed parameter with value '' (empty string). I use a generic action because I handle all my routes in the same way, so suddenly I find the url of my app looks like this '/?0=%2F' or like this '?0=' or worse - if I go to 'blah' the url will look like this '/?=%2Fblah'I've read the path-to-regex documentation, and I found out that this is the desired behavior for the unnamed parameters
(.*)
, but this is not the desired behavior for wild card path. Please provide another way to handle wild card paths, while keeping the same behavior for unnamed parameters, as they are not the same case.Side note: I love your work, I have been searching for a universal router for about a year before I have found your package, and I have not used any other router since. Brilliant work, great flexibility. I will submit a PR soon to add more recipes.