umi3采用的是都是React Router5,hooks传递参数使用useParams和useRouteMatch等方式。
但是父级路由是无法访问子路由的参数的,比如
{
path: '/parent',
component: '@/components/ParentLayout',
routes: [
{
path: '/parent/info/:id',
component: './parent/Info',
},
{
path: '/parent/optInfo/:id',
component: './parent/OptInfo',
},
],
},
应改为:
{
path: '/parent/:type/:id',
component: '@/components/ParentLayout',
routes: [
{
path: '/parent/info/:id',
component: './parent/Info',
},
{
path: '/parent/optInfo/:id',
component: './parent/OptInfo',
},
],
},
通过useParams获取参数
import { useParams, useRouteMatch } from 'umi'
console.log(useParams())