Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何设置动态路由 #1

Open
penggelies07 opened this issue Feb 1, 2018 · 1 comment
Open

如何设置动态路由 #1

penggelies07 opened this issue Feb 1, 2018 · 1 comment

Comments

@penggelies07
Copy link

我按照你的思路来配置路由

import asyncComponent from '../AsyncComponent'
import {renderRoutes} from 'react-router-config'

const routes = [
  { 
    path: '/',
    component: asyncComponent(() => import('../views/Home')),
    routes: [
      {
        path: '/categories',
        component: asyncComponent(() => import('../views/Categories')),
      }, {
        path: '/categories/:categoryId',
        component: asyncComponent(() => import('../views/Two'))
      }
      //  {
      //  path: '/two',
      //  component: asyncComponent(() => import('../views/Two'))
      // }
    ]
  }
]

const MBRoutes = renderRoutes(routes)

export default MBRoutes

然后在页面中进行跳转

 onEnter = (categoryId: string) => {
    this.props.history.push(`/categories/${categoryId}`)
  }

url变了,但是没有跳转,可能没有匹配到路由。我试了一下写成/two就可以,请问一下这个该怎么正确实现动态路由/categories/:categoryId呢?

@penggelies07 penggelies07 changed the title 设置动态路由如何 如何设置动态路由 Feb 1, 2018
@wangweianger
Copy link
Owner

@penggelies07

import {renderRoutes} from 'react-router-config'
const routes = [
    { 
        path: '/',
        component: asyncComponent(() => import('../views/Home')),
    },
    {
        path: '/categories',
        component: asyncComponent(() => import('../views/Categories')),
    },
    {
        path: '/categories/:categoryId',
        component: asyncComponent(() => import('../views/Two'))
    },
    {
        path: '/two',
        component: asyncComponent(() => import('../views/Two'))
    }
]
const MBRoutes = renderRoutes(routes)
export default MBRoutes

你好 你可以把路由提出来,这样写试试吧

@wangweianger wangweianger reopened this Feb 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants