vue3.0添加路由router

1.首先下载vue-router  yarn add vue-router@next

2.创建文件router/index.js

import { createRouter, createWebHashHistory } from "vue-router";

const routes = [

          {

              path:"/",

              name:"home",

              component:()=>import("@/components/home.vue")

          }

        ]

const router = createRouter({

  history: createWebHashHistory(),

  routes

});

export default router;

vue3.0添加路由router_第1张图片
图片

3.在main.js引入router,挂载router


vue3.0添加路由router_第2张图片
挂载router

4.在app.vue中放入路由


vue3.0添加路由router_第3张图片
app.vue

git克隆地址 https://github.com/GitfishHub/vue.3.0easyencapsulation.git

你可能感兴趣的:(vue3.0添加路由router)