假如以下代码是我主页的路由 ,路由主要分 /app 和 /something ,然后 /app下还有三个路由 /app/home,/app/company,/app/about, 假如我想把除了以上路由的其他路由都指向 /app/home 改怎么做
比如 /app/abcd 我的网站没有这个页面 用户手动输入后自动跳转到/app/home
const AppMain = () => (
<div>
<Navbar/>
<Switch>
{/* <Redirect exact from='/' to='/app/home'/> */}
<Redirect exact from='/app/' to='/app/home'/>
<Route exact path="/app/home" component={Main}/>
</Switch>
<Route path="/app/company" component={Company}/>
<Route path="/app/about" component={AboutMe}/>
<Footer/>
</div>
);
class App extends Component {
render() {
return (
<Router>
<div className="App">
{/* 主页入口 */}
<Route path='/app' component={AppMain}/>
{/* 完全空页面 备用 */}
<Route path='/something' component={Something}/>
</div>
</Router>
);
}
}
<Redirect from="/app" to="/app/home"/>