Javascript 当位置与任何路由不匹配时重定向到索引位置

Javascript 当位置与任何路由不匹配时重定向到索引位置,javascript,reactjs,react-router,Javascript,Reactjs,React Router,当路由不匹配时,我想重定向到索引路由 route.js <Route path={"/"} component={BulletinBoardApp}> <IndexRoute component={BulletinBoardAppItems} /> <Route path={"savedMessages"} component={BulletinBoardAppItems} /> <Route path={"urgentMessa

当路由不匹配时,我想重定向到索引路由

route.js

<Route path={"/"} component={BulletinBoardApp}>
    <IndexRoute component={BulletinBoardAppItems} />
    <Route path={"savedMessages"} component={BulletinBoardAppItems} />
    <Route path={"urgentMessages"} component={BulletinBoardAppItems} />
  </Route>
我想重定向到。有办法吗


首选/正确的解决方案是什么?

将*放在路径中,这样每当它与任何路由不匹配时,它都会重定向到您将提到的默认路由

<Route path="*" component={PageNotFound} />

创建PageNotFound组件

<Route path="*" component={PageNotFound} />