router/index.js
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Test from '../views/Test.vue'
import NotFound from '../views/NotFound.vue';
Vue.use(VueRouter)
const routes = [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/test/:id',
name: 'Test',
component: Test
},
{
path: '/about',
name: 'About',
component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
},
{
//捕获404,not found
path: '*',
name: 'NotFound',
component: NotFound
},
]
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
export default router
views/Notfound.vue
<template>
<div>
404,页面走失了
</div>
</template>
<script>
export default {
}
</script>
<style lang="scss" scoped>
</style>
效果截图: