Router: Redirect to route when nothing is matched

Created on 21 Aug 2018  路  4Comments  路  Source: reach/router

This is a really great router that does most of the things i didn't thought was possible since no one made it before this one :-) !

However i am struggling with one thing, default routes.

I tried to find a way of handling default routes. As a sample i would like "/" to fallback to "/dashboard/home". But "/dashboard" should also go to "/dashboard/home" :-)

As a background story i am working on a large application with nested routers. I would like each router to fallback to a default page if nothing is matched while updating the url :-)

Here is the codesandbox demonstrating the issue: https://codesandbox.io/s/zxwm87v93.

Please let me know if something is missing :-)

Most helpful comment

Have you tried using the default prop on the Redirect?
See: https://codesandbox.io/s/myr1ny60x9

I made changes to both src/index.js and src/views/Dashboard/index.js

All 4 comments

Have you tried using the default prop on the Redirect?
See: https://codesandbox.io/s/myr1ny60x9

I made changes to both src/index.js and src/views/Dashboard/index.js

Awesome, didn't try that :-)

Your solution actually works as i wanted it to. However, now when it works i discovered that the redirect component adds the previous url to the history. Is there any way to use the replace behavior :-) ?

It looks like the implementation should be using replace by default, and it seems to be working that way for me in the browser. If it's not working that way for you, it could be a bug in codesandbox.io.

Great, seems to be a bug in codesandbox :-) Cool, thank you for the guidence, really helped me out :-) !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

florian-bd picture florian-bd  路  3Comments

Kadrian picture Kadrian  路  5Comments

magnusarinell picture magnusarinell  路  3Comments

benwiley4000 picture benwiley4000  路  4Comments

ryanflorence picture ryanflorence  路  4Comments