frontarm / navi

🧭 Declarative, asynchronous routing for React.
https://frontarm.com/navi/
MIT License
2.07k stars 71 forks source link

routing with optional parameters #119

Open chinds185a opened 5 years ago

chinds185a commented 5 years ago

Following on from this issue #85 could you point me in the right direction where this work might need to be done?

My previous routing logic relied on react-router supporting optional params and not only splitting on a / i.e. my URL could have optional param of .amp

In react-router this works: /:language(${languageRegex})/page/:id(${idRegex}):amp(.amp)?

In navi id & amp get combined into a single param and thus never match correctly

jamesknelson commented 5 years ago

So basically the way matching works in Navi, is that the remaining part of the route is passed to a mount(), which splits it along the first / character, ignores the second half, and tries to match the first half with each of its supplied patterns.

To support more complex patterns, you'd need to modify this behavior. Here's a few relevant sections of code: