社区微信群开通啦,扫一扫抢先加入社区官方微信群
社区微信群
做404页面路由 使用hash可以使用 * 作为path 或者动态 /:id
但是 history 建议使用 /:id 作为404 重定向 虽然 * 可以
但是 最新版 会报错
{
path: '*',
name: 'form',
component: () => import(/* webpackChunkName: "about" */ '../views/404.vue')
},
{
path: '*',
name: 'form',
component: () => import(/* webpackChunkName: "about" */ '../views/404.vue')
},
export const routes = [
{
path: '/',
name: 'Home',
component: Home,
children: [
{
path: '/', // 必须含有默认 才能动态
component: {
render: h => h('div',{},12311)
}
}
]
},
{
path: '/about',
name: 'About',
// 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/About.vue')
}
]
import Tex from "./Text";
获取如下
component: (resolve) => require(["./Text.vue"], resolve), //将组件用require引进来
this.$router.options.routes[0].children.push({
//插入路由
name: "list",
path: "/list",
component:Tex
});
this.$router.addRoutes(this.$router.options.routes); //调用addRoutes添加路由
this.$router.push({
path: "/list",
});
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!