Closed jchiellini closed 6 years ago
Why did you close it @jchiellini ?
Hi @jchiellini,
Could you provide the answer?
I'm facing the same issue. I tested multiple solutions from path-to-regexp
but I'm not able to match the route with two optionals parameters in the row.
Thanks!
Adding ? is indeed the answer. https://github.com/fridays/next-routes/issues/86#issuecomment-323854224 This works with multiple optional params.
routes.add({
name: 'some-cool-route',
pattern: '/foo/bar/:id/:banana?/:anchovy?/:lemon?',
page: 'superpage',
})
Router.pushRoute('some-cool-route', {
id: 'asdf',
lemon: 'boop',
})
Adding ? always matches the index route
.add({
name:'/',
pattern:'/:country?/:lang?',
page:'index'
})
.add({
name:'our-firm',
pattern:'/:country?/:lang?',
page:'our-firm'
})
On navigation to http://localhost:3000/en/our-firm it opens index page but it should open our-firm
Is there a syntax for optional params?
// Commonly used syntax Router.add('pageID', '/page-path/:optional1?/:optional2?')
Did I miss something in the docs or just have not thought of an implementation to achieve this?