umi手动路由配置

946 阅读1分钟

手动路由配置

在配置路由参数的过程中,对应的component文件要写children参数,否则只会匹配一级路由,子路由内容不展示

{
        path: '/test',
        title: 'name',
        component: '@/pages/test/rank/index',
        routes: [
          {
            path: '/test/rank/index',
            title: 'name',
            component: '@/pages/test/rank/child',
          },
        ]
}
@/pages/test/rank/index文件:
import React from 'react';
const Index = () => {
  return <div>'test-首页'</div>;
};
export default Index;
//此文件中未写children参数,导致匹配子路由test/rank/index时未进行渲染


import React from 'react';
const Index = () => {
  return <div>'test-首页'{children}</div>;
};
//访问test/rank/index此时会展示子路由对应的组件内容