对于单页面应用来说,路由是核心功能。而 Umi 的路由既支持配置式,又支持约定式
https://zhuanlan.zhihu.com/p/398655814

动态路由

  1. pages/
  2. [id].js
  3. 生成的路由在 src/.umi/core/routes.ts
  4. const routes = [
  5. {
  6. path: '/:id',
  7. exact: true,
  8. component: require('@/pages/[id].js').default
  9. }
  10. ]
  11. umi2 动态路由
  12. $id.js

权限控制

admin 权限参考

  1. export default [
  2. {
  3. // 没有 name属性,左侧菜单里面就不显示
  4. // name: 'list.table-list',
  5. icon: 'table',
  6. path: '/list',
  7. component: './TableList',
  8. },
  9. {
  10. path: '/admin',
  11. name: 'admin',
  12. icon: 'crown',
  13. access: 'canAdmin',
  14. component: './Admin',
  15. routes: [
  16. {
  17. path: '/admin/sub-page',
  18. name: 'sub-page',
  19. icon: 'smile',
  20. component: './TableList',
  21. },
  22. ],
  23. },
  24. ]