reactjs - 将路由器切换为交换机/嵌套路由?
问题描述
我正在制作一个反应应用程序,我遇到了我必须在路线内有路线的问题,我正在努力解决它。
这是怎么回事:
1)如果您已登录,您将面对页面登录或主页。
function App() {
return (
<div className='App'>
<BrowserRouter>
<Router>
<Switch>
<Route exact path='/login' component={Login} />
<Route exact path='/' component={Home} />
</Switch>
</Router>
</BrowserRouter>
</div>
);
}
export default App;
2 ) 主页由导航栏、仪表板和页脚组成,路由路由将仪表板组件与特定组件如新闻、计划等切换。
const Home = () => (
<div className='container-ome'>
<Header />
<Router>
<Switch>
<Dashboard />
<Route exact path='/newspost' component={Newspost} />
<Route exact path='/newslist' component={Newslist} />
<Route exact path='/user' component={User} />
</Switch>
</Router>
<Footer />
</div>
);
export default Home;
```
3 ) The other components will have infos, and a link to get back to the dashboard
```const Newspost = () => (
<div className='container-newspost'>
<h1> Newpost Title</h1>
<Link to='/'>back to dashboard</Link>
</div>
);```
Nothing works like i would, what did i missed ?
Should i declare al my routes in app ?
Be gentle i'm a noobie :(
Thanks in advance
解决方案
推荐阅读
- mysql - 即使类别为空,MySQL 也将产品与类别树连接起来
- ios - 如何从 Mac OS X Catalina 上传 IPA 文件到 App Store
- python - 硬币找零计算器的递归错误 - 无法调试
- variables - 在 API Katalon-Studio 中使用基本身份验证中的变量
- amazon-web-services - Hive 在 EMR 5.19 中使用 hive-2.3.3 返回 NULL 值
- java - 如何将 int[][] 字符串转换为 List
- >
- php - 计算使用 Laravel 插入的行数?
- java - 每个安装的程序都有自己的默认编译器吗?
- c# - 在执行下一个 C# 之前等待用户再次复制某些内容的剪贴板
- project-reactor - 可以或应该重用 Schedulers.newElastic 吗?