fridays / next-routes

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

History lost when routes use the same component #159

Closed claudiamatosa closed 1 year ago

claudiamatosa commented 6 years ago

Hey all,

This may be a bit of an edge case.

Given that you have two routes that use the same component:

routes
  .add('foo', '/foo/:param', 'FooBar')
  .add('bar', '/bar/:param', 'FooBar')

When you navigate between these pages and the param values are equal, next will call replaceState instead of pushState, which means that the browser's back button becomes useless.

This happens because, when building the route, next-routes sets href to be page name + query params: https://github.com/fridays/next-routes/blob/master/src/index.js#L148 (which means /FooBar?param=abc).

Then, Link from next calls the change method with href: https://github.com/zeit/next.js/blob/canary/lib/link.js#L75

And finally, router checks if the pathname or query params change before deciding between pushState or replace state: https://github.com/zeit/next.js/blob/canary/lib/router/router.js#L161

My question is, is this intended behaviour? Is there a reason why href is set to the name of the page and as contains the real path?

Thank you