fridays / next-routes

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

Shallow routing in next-routes? #219

Closed JiiB closed 6 years ago

JiiB commented 6 years ago

I was wondering if there is shallow routing in next-routes?

There is a specific use case in my app, where I need to change the route but without calling getInitialProps again. The default Next Router supports that, see:

https://github.com/zeit/next.js#shallow-routing

How can I change the route on client side without calling getInitialProps again?

JiiB commented 6 years ago

I guess it can be achieved with Router.replaceRoute()

assimelha commented 6 years ago

Router.replaceRoute(name, params, options) in options put {shallow: true}

matheus-rosin commented 5 years ago

So I am using next-routes in my project, and the structure of one of my routes is:

.add('/search/:something1?/location/:something2?', 'search')

which means that all of the routes that matches this pattern will go to search page.

The issue is that, even though I navigate between two pages that resolve both to search (and using { shallow: true }), getInitialProps get called.

And more: if I send Router.pushRoute(route, null, { shallow: true }), I get the error Cannot read property 'shallow' of null.

So I don't know what is happening, but it seems to me that there is some confusion going on.

Any help?

Thanks

matheus-rosin commented 5 years ago

Actually, if I pass it in the second argument (instead of in the third), it works. Strange.