简体   繁体   English

如何获取路线的所有名称?

[英]How to get list all name of routes?

export const routes: RouteRecordRaw[] = [
  {
    path: '/',
    name: 'Main',
    component: () => import('~/pages/Main.vue'),
    children: [],
  },
  {
    path: '/auth',
    name: 'Auth',
    component: () => import('~/pages/Auth.vue'),
    meta: {
      isAuthPage: true,
    },
  },
  {
    path: '/movies',
    name: 'Movies',
    component: () => import('~/pages/Movies.vue'),
    meta: {
      isAuthPage: true,
    },
  },
  {
    path: '/tv-shows',
    name: 'TVShows',
    component: () => import('~/pages/TVShows.vue'),
    meta: {
      isAuthPage: true,
    },
  },
]

I expected type Pages = 'Main' | 'Auth' | 'Movies' | 'TVShows我预计type Pages = 'Main' | 'Auth' | 'Movies' | 'TVShows type Pages = 'Main' | 'Auth' | 'Movies' | 'TVShows

What do you mean by you expected?你的预期是什么意思? Do you want to create this type?您要创建此类型吗? You could do that like this:你可以这样做:

export const routes = [
  {
    path: '/',
    name: 'Main',
    component: () => import('~/pages/Main.vue'),
    children: [],
  },
  {
    path: '/auth',
    name: 'Auth',
    component: () => import('~/pages/Auth.vue'),
    meta: {
      isAuthPage: true,
    },
  },
  {
    path: '/movies',
    name: 'Movies',
    component: () => import('~/pages/Movies.vue'),
    meta: {
      isAuthPage: true,
    },
  },
  {
    path: '/tv-shows',
    name: 'TVShows',
    component: () => import('~/pages/TVShows.vue'),
    meta: {
      isAuthPage: true,
    },
  },
] as const

type Pages = typeof routes[number]["name"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM