vue3+vite 路由创建

1.npm install vue-router --save

2.src下创建router文件夹及index.ts文件,文件内容

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

import home from "../views/home.vue"

const routes = [
    {
        path: '/',
        redirect: '/home'
    },
    {
        path: '/home',
        component: home
    }
]

export default createRouter({
    history: createWebHashHistory(),
    routes
})
3.main.ts引入上面文件

 

 4.需要用到路由的地方添加

<router-view></router-view>

 

posted @ 2022-02-15 10:56  申伸  阅读(604)  评论(0)    收藏  举报