在反应中路由一组路由

时间:2020-02-04 15:39:51

标签: reactjs react-router-dom

这是我的代码:

<Switch>
 {
   modules.map((m: any[]) => {
    m.map((subm, idx: number) => {
     return (<Route exact path={subm.routeProps.path} component={subm.routeProps.component} key={idx}></Route>)})})
 }
</Switch>

我猜路由不正确,我猜是因为我有一组Route。

模块是数组列表(每个模块在一起都有一些路径)

下面是一个模块示例(身份验证):

import Login from '../../components/login/login'
import SignUp from '../../components/signup/signup'

export default [
    {
        routeProps: {
            path: '/login',
            component: Login
        },
        name: 'Login'
    },
    {
        routeProps: {
            path: '/signup',
            component: SignUp
        },
        name: 'Sign Up'
    }
]

主要导出的 index.tsx 是:

import Analytics from './analytics'
import Dashboard from './dashboard'
import Games from './games'
import Users from './users'
import Authentication from './authentication'


export default [
    Dashboard,
    Analytics,
    Games,
    Users,
    Authentication
]

0 个答案:

没有答案