React router v4中去掉了IndexRoute,那么如何设置默认路由呢~class MainComponent extends Component{ render(){ return <div id="stage"> <Switch> <Route exact path='/' component={IndexComponent}/> <Route path='/user' component={UserComponent}/> </Switch> </div> }}网上有这样写的:class MainComponent extends Component{ render(){ return <div id="stage"> <div><IndexComponent></div> <Switch> <Route exact path='/' component={IndexComponent}/> <Route path='/user' component={UserComponent}/> </Switch> </div> }}我这样写的时候会出现渲染别个页面组件的时候都会把IndexComponnet这个默认页面组件渲染了出来,麻烦解答一下。
1 回答
ABOUTYOU
TA贡献1812条经验 获得超5个赞
let Routes = (<Router>
<div>
<Link activeClassName="active" exact={true} to={{pathname: '/index'}}>首页</Link>
<Link activeClassName="active" to={{pathname: '/error',search:'?msg=错误页面'}}>错误页面</Link>
<div className="route-content">
<Switch>
<Route path="/index" exact component={HomePage}/>
<Route path="/error" component={errorPage}/>
<Redirect path="/" to={{pathname: '/index'}} />
</Switch>
</div>
</div>
</Router>)
添加回答
举报
0/150
提交
取消