Commit 54967fda authored by lipengcheng 's avatar lipengcheng

feat: 优化路由引入;增加错误页面

如上
parent 96738d8f
<template>
<div class="layout-404">
<router-view></router-view>
</div>
</template>
<script>
export default {
name: 'Error',
data() {
return {}
},
created() {},
mounted() {}
}
</script>
<style scoped lang="scss">
/* @import url(); 引入css类 */
</style>
export default {
path: '/',
name: 'home',
meta: {
layout: 'DefaultLayout',
title: '首页'
},
component: () => import(/* webpackChunkName: "about" */ '@/views/home.vue')
}
import Vue from 'vue' import Vue from 'vue'
import VueRouter from 'vue-router' import VueRouter from 'vue-router'
// import Bao3 from '../views/bao3.vue'
Vue.use(VueRouter) Vue.use(VueRouter)
const routes = [ let routes = []
{
path: '/', // 通配符404页面
name: 'home', const wildcardRoutes = {
meta: { path: '*',
layout: 'DefaultLayout', name: '*',
title: '首页' // hidden: true,
}, meta: {
component: () => import(/* webpackChunkName: "about" */ '../views/home.vue') layout: 'error',
}, title: '错误页面'
{
path: '/page1',
name: 'Page1',
component: () => import(/* webpackChunkName: "about" */ '../views/page1.vue')
}, },
{ component: () => import(/* webpackChunkName: "404" */ '@/views/404.vue')
path: '/page2', }
name: 'page2',
meta: { // 引入所有路由文件
layout: 'layout-a', function importAll(r) {
title: '页面2' r.keys().forEach((path) => routes.push(r(path).default || r(path)))
}, }
// route level code-splitting importAll(require.context('@/router/', true, /\.router\.js/))
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited. routes.push(wildcardRoutes)
component: () => import(/* webpackChunkName: "about" */ '../views/page2.vue')
}
]
const router = new VueRouter({ const router = new VueRouter({
mode: 'history', mode: 'history',
......
export default {
path: '/page1',
name: 'Page1',
component: () => import(/* webpackChunkName: "about" */ '../views/page1.vue')
}
export default {
path: '/page2',
name: 'page2',
meta: {
layout: 'layout-a',
title: '页面2'
},
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ '../views/page2.vue')
}
<template>
<div class="page-404">
<h1>404</h1>
</div>
</template>
<script>
export default {
data() {
return {}
},
created() {},
mounted() {}
}
</script>
<style scoped lang="scss">
/* @import url(); 引入css类 */
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment