react-router 嵌套路由元素,子元素的相关内容加载不出来,而且整个地址无法匹配
想用外层路由实现模板页、登录、404等页面,
在模板页内层用子路由实现内容的动态加载
// 请把代码文本粘贴到下方(请勿用图片代替代码)
//外层路由 App.js
render() { return ( <Switch> <Route exact component={Home} path="/" /> <Route component={Login} path="/login" /> <Route component={NotFound} /> </Switch> ) }
//内层Home.js
render() { return ( <Layout> <Header>Some Info.</Header> <Content> <Switch> <Route exact path="/" component={MyLayout} /> <Route path="/temperature/month" component={TemperatureMonth} /> <Route path="/temperature/day" component={TemperatureDay} /> </Switch> </Content> </Layout> ); }
输入http://127.0.0.1:3000/temperature/month,结果匹配到外层NotFound.
MM们