编程式导航

编程式导航







路由别名

给路由取个名字就能不用书写那么长吃url了直接写别名也可以跳转

import Vue from 'vue'
import VueRouter from 'vue-router'

import Home from './views/Home.vue'
import Films from './views/Films.vue'
import Film from './views/Film.vue'
import Cinemas from './views/Cinemas.vue'
import Center from './views/Center.vue'
// import Page404 from './views/404.vue'

Vue.use(VueRouter)

const router = new VueRouter({
  routes: [
    {
      path: '/',
      component: Home,
      children: [
        {
          path: 'films/nowPlaying',
          component: Films
        },
        {
          path: 'cinemas',
          component: Cinemas
        },
        {
          path: 'center',
          component: Center
        },
        {
          path: '',
          redirect: '/films/nowPlaying'
        }
      ]
    },
    {
      path: '/film/:filmId',
      name: 'detail',
      component: Film
    },
    {
      path: '*',
      // component: Page404 // 404
      redirect: '/films/nowPlaying'
    }
  ]
})

export default router

你可能感兴趣的:(编程式导航)