首页 > 解决方案 > 将路由器切换为交换机/嵌套路由?

问题描述

我正在制作一个反应应用程序,我遇到了我必须在路线内有路线的问题,我正在努力解决它。

这是怎么回事:

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

标签: reactjsroutesreact-router

解决方案


推荐阅读