在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ React 怎么把頁面url沒有正確指向的路由 指向首頁

React 怎么把頁面url沒有正確指向的路由 指向首頁

假如以下代碼是我主頁的路由 ,路由主要分 /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"/>

2017年4月21日 10:09