定義路線的不同方式

路線/ index.js

  import About from '@/components/About'

  const router = new Router({
     
    routes: [
     {
       path: '/',
       name: 'home',
       component: {template: "<div>Home</div>"}
     },

     {
       path: '/about',
       component: About
     },

     require('./work').default,
     
     // - NOT FOUND
     {path: '/404', component: {template: "<div>404 not found.</div>"}},
     {path: "/*", redirect: "/404"}
   ]
 });
 
 export default router

路線/ work.js

import Work from '@/components/Work/Work';
import Workitem from '@/components/Work/Workitem';

export default { 
  path: '/work', 
  name: 'work', 
  component: Work, 
  children: [
    {path: '/all', component: {template: '<div>Some text</div>'}},
    {path: ':id', name: 'work.view', component: Workitem},
    {path: ':id/edit', name: 'work.edit', component: Workitemedit},
  ],
  meta: {requiresAuth: true}
}