Closed claudiamatosa closed 1 year 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.
next
replaceState
pushState
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).
next-routes
href
/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
Link
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?
as
Thank you
Hey all,
This may be a bit of an edge case.
Given that you have two routes that use the same component:
When you navigate between these pages and the param values are equal,
next
will callreplaceState
instead ofpushState
, which means that the browser's back button becomes useless.This happens because, when building the route,
next-routes
setshref
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
fromnext
calls the change method withhref
: https://github.com/zeit/next.js/blob/canary/lib/link.js#L75And 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 andas
contains the real path?Thank you