首页 > 其他 > 详细

vue3 中 vue-router 的使用

时间:2021-06-17 17:08:30      阅读:37      评论:0      收藏:0      [点我收藏+]

安装: npm install vue-router@4 

路由:

// src/router/index.js文件
import {createRouter, createWebHistory} from "vue-router" import Home from ‘../views/Home.vue‘

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")
  }
]
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: [
    //...
  ],
})

 

vue3 中 vue-router 的使用

原文:https://www.cnblogs.com/Maraitowa/p/14892935.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!