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,
},
component: () => import(/* webpackChunkName: "about" */ '../views/home.vue')
},
{
path: '/page1',
name: 'Page1',
component: () => import(/* webpackChunkName: "about" */ '../views/page1.vue')
},
{
path: '/page2',
name: 'page2',
meta: { meta: {
layout: 'layout-a', layout: 'error',
title: '页面2' title: '错误页面'
}, },
// route level code-splitting component: () => import(/* webpackChunkName: "404" */ '@/views/404.vue')
// 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') // 引入所有路由文件
} function importAll(r) {
] r.keys().forEach((path) => routes.push(r(path).default || r(path)))
}
importAll(require.context('@/router/', true, /\.router\.js/))
routes.push(wildcardRoutes)
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