vue3中使用vue-router


安装vue-router

npm install vue-router@4.0.0-beta.13

创建src/router/index.js

import { createRouter, createWebHashHistory } from 'vue-router'

const router = createRouter({
  history: createWebHashHistory(), // hash模式:createWebHashHistory,history模式:createWebHistory
  routes: [
    {
      path: '/',
      redirect: '/home'
    },
    {
      path: '/home',
      name: 'home',
      component: () => import(/* webpackChunkName: "home" */ '@/views/home.vue'),
      meta: {
        index: 1
      }
    },
    {
      path: '/test',
      name: 'test',
      component: () => import(/* webpackChunkName: "login" */ '@/views/testDemo.vue'),
      meta: {
        index: 1
      }
    } 
  ]
})

export default router

 

main.js中

import router from './router'

app.use(router)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM