Im having a little problem here, Im trying to put a page 404 when the url is invalid, the problem is, it's loading all the time, for example if a try to access my home page will redirect to the page 404, I've tried some examples but not success :
#redirect in all pages
<Redirect exact={true} from='*' to='/404' /> #test 1
<Redirect from='*' to='/404' /> #test2
#appear in the bottom of the pages
<Route exact={true} path='*' component={asyncComponent(() => import('./containers/Page/404'))} />
<Route path='*' component={asyncComponent(() => import('./containers/Page/404'))} />
try having in this way
<Switch>
<Route path="/" exact component={Home}/>
<Route path="/will-match" component={WillMatch}/>
<Route component={NoMatch} />
</Switch>
This is how I have configured the routes in a recent react project.
<Route exact path={`${process.env.PUBLIC_URL}/`} component={Main} />
<Route path='/new' component={ReportCreator}/>
<Route path='/reports/:id' component={Report}/>
<Route component={Page404} />
Using BrowserRouter
and Switch
router.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.