vue3 中 vue-router 的使用
作者:互联网
安装: npm install vue-router@4
路由:
// src/router/index.js文件const routes = [ { path: '/', name: 'Home', component: Home, children: [ { path: "/dashboard", name: "dashboard", meta: { title: '系统主页' }, component: () => import("../views/Dashboard.vue") } ] }, { path: "/login", name: "Login", meta: { title: '登录' }, component: () => import("../views/Login.vue") } ]
import {createRouter, createWebHistory} from "vue-router" import Home from '../views/Home.vue'
const router = createRouter({ history: createWebHistory(process.env.BASE_URL), routes }) export default router
上述使用的是 history 模式,hash 模型需要做的改变如下(需将createWebHistory改为createWebHashHistory):
import { createRouter, createWebHashHistory } from 'vue-router' const router = createRouter({ history: createWebHashHistory(), routes: [ //... ], })
标签:vue,const,import,createRouter,vue3,router,Home 来源: https://www.cnblogs.com/Maraitowa/p/14892935.html