fridays / next-routes

Universal dynamic routes for Next.js
MIT License
2.47k stars 230 forks source link

Navigate using path and pass params via params props #75

Closed adrianha closed 7 years ago

adrianha commented 7 years ago

Hi @fridays , Is it possible to navigate like this? Router.pushRoute('/search', { id: 1, name: 'abc' }); It looks like that params is not passed when given the path in the first parameter. Heres the example repo: Example

fridays commented 7 years ago

Hi @adrianha you can either use route name & params or a url to resolve:

// routes.js
routes.add('search', '/search/:id/:name')

// Route name and params
Router.pushRoute('search', {id: 1, name: 'abc', more: 'things'})

// Or resolve url
Router.pushRoute('/search/1/abc?more=things')
adrianha commented 7 years ago
// Or resolve url
Router.pushRoute('/search/1/abc?more=things')

Hello @fridays , If i resolved the url using that method, i found that the third options on pushRoute wont take an effect. Example:

/** getInitialProps is still called */
Router.pushRoute('/search/1/abc?more=things', {}, { shallow: true });
/** getInitialProps is not called as expected which means the options is working */
Router.pushRoute('search', { id: 1, name: 'abc', more: 'things' }, { shallow: true });

Is there any way to pass the options when i resolve the route using url? Thanks

fridays commented 7 years ago

Pass options as the second argument. When resolving by URL, there is no params argument. We need to make this clear in the readme.