【发布时间】:2018-12-28 17:07:28
【问题描述】:
我有一个路由文件,其中我的路由嵌套在索引组件下。 但是,我想要一些其他组件,登录我不想嵌套在任何组件下,但我想用它来重定向到'/'主路由。
如果我使用 Div 标签,那么它会弄乱我的模板。 我在 Switch 标签内添加登录组件 - 路由。 如果我不这样做,我会得到 React 只能有一个子错误。
有谁知道如何做嵌套路由和非嵌套路由?请帮忙。
这是我的路由器文件。
import React, { Component } from 'react';
import './App.css';
import { Provider } from 'react-redux';
import store from './store/store';
import { Router, Route , Switch } from 'react-router-dom';
import Index from './actions/indexToggle/indexActions';
import FirstDashboard from './_layouts/views/firstDashboard';
import SecondDashboard from './_layouts/views/secondDashboard';
import ThirdDashboard from './_layouts/views/thirdDashboard';
import FourthDashboard from './_layouts/views/fourthDashboard';
import history from './history';
import FifthDashboard from './_layouts/views/fifthDashboard';
import Login from './_layouts/views/Login/login';
const Main = () => (
<Provider store={store}>
<Router history={history}>
<Switch>
<Index>
<Route exact path='/overview1' component={FirstDashboard} />
<Route exact path='/overview2' render={(props) => <SecondDashboard {...props} show="show" /> } />
<Route exact path='/overview3' component={ThirdDashboard} />
<Route exact path='/overview4' component={FourthDashboard} />
<Route exact path='/overview5' component={FifthDashboard} />
</Index>
<Route path='/login' component={Login} />
</Switch>
</Router>
</Provider>
)
export default Main;
【问题讨论】:
标签: reactjs react-router react-router-v4 react-router-dom