router
router copied to clipboard
Unexpected behaviour of dynamic routes with rest syntax
Which package manager are you using? (Yarn is recommended)
yarn
Summary
I have a basic layout.
- App Index screen
app/index.tsx
- Two screens with dynamic routes:
-
app/view/[...pathVariable].tsx
-
app/[...pathVariable]/index.tsx
.
-
The first dynamic route works fine (app/view/[...pathVariable].tsx
).
If I push from /
to /view/foo/bar
everything works as expected and the URL looks like /view/foo/bar
and has no GET parameters appended (which is what I expect).
On the second dynamic route, if I push from /
to /foo/bar
, I land on app/[...pathVariable]/index.tsx
which is correct, but now GET parameters are being appended and the URL looks like /foo/bar?pathVariable=foo&pathVariable=bar
If I navigate from /
to /foo/bar
and then try /
again, it does not navigate to app/index.tsx
screen but removes the GET parameters. (And the URL is then still: /foo/bar
)
Another oddity: If I go from /
to /foo/bar
then to /view/foo/bar
and then back to /foo/bar
the screen gets rerendered and usePathname
var changes from /foo/bar
to /foo/bar/
(console logs twice, extra slash at end) on this screen.
Are routes like app/[...pathVariable]/index.tsx
supported?
Minimal reproducible example
Here is a working codesandbox showcasing this behaviour: