Next-routes: Shallow routing in next-routes?

Created on 11 Aug 2018  路  4Comments  路  Source: fridays/next-routes

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?

Most helpful comment

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

All 4 comments

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

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

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

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

Was this page helpful?
0 / 5 - 0 ratings