首页 新闻 搜索 专区 学院

react-router4怎么嵌套路由啊?我的二级路由没有显示,也不报错是怎么回事?

0
[待解决问题]

下面是首页路由的配置

class RouterMap extends React.Component {
    render() {
        return (<BrowserRouter><div>
            <Switch>
            <Route path='/' exact component={Home}/>
             <Route path="/users" component={Users}/>
            <Route path='/city' component={City}/>
            <Route path='/city2' component={City2}/>
            <Route path='/result' component={Result}/>
            <Route match='match' path='/dashboard' exact component={Dashboard}/>
            <Route path='/dashboard/id'  component={Dashboard200}/>
            </Switch>
        </div></BrowserRouter>)
    }
}

下面是子路由页面的配置

class Dashboard extends React.Component {
    componentDidMount(){
        //console.log(this.props)
    }
    render() {
        console.log(this.props)
        const match=this.props.match
        return (<div>
            <div>123</div>
            <Switch>
                <Route path={`${match.url}/2`} component={Dashboard6}/>
                <Route path={`${match.url}/3`} component={Dashboard1}/>
                <Route path="/2" component={Dashboard1}/>
            </Switch>
         </div>)
    }
}
web老猿的主页 web老猿 | 菜鸟二级 | 园豆:206
提问于:2018-07-04 20:26
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册