猫爱水煮鱼
猫爱水煮鱼
  • 发布:2018-07-04 18:46
  • 更新:2018-07-04 18:46
  • 阅读:2174

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

分类:HTML5+

下面是首页路由的配置```javascript
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>)
}
}

下面是子路由的配置
```javascript  
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>)  
    }  
}

上面子路由怎么都不行,能访问的路径只有空,和斜杠,其他都不行,而且也没有任何报错

2018-07-04 18:46 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复