首页 > 其他分享 >030、Vue3+TypeScript基础,路由中History和HashHistory的区别

030、Vue3+TypeScript基础,路由中History和HashHistory的区别

时间:2024-08-18 23:04:17浏览次数:11  
标签:About TypeScript vue Vue3 component HashHistory import Home path

01、index.ts路由代码如下:

//创建路由并暴露出去
import {createRouter, createWebHistory} from 'vue-router'
import Home from '@/view/Home.vue'
import About from '@/view/About.vue'
import News from '@/view/News.vue'

const router = createRouter({
    history: createWebHistory(),
    routes: [
        {path: '/home', component: Home},
        {path: '/about', component: About},
        {path: '/news', component: News},
    ]
})

export default router

02、效果如下

 03、index.ts代码如下:

//创建路由并暴露出去
import {createRouter, createWebHashHistory} from 'vue-router'
import Home from '@/view/Home.vue'
import About from '@/view/About.vue'
import News from '@/view/News.vue'

const router = createRouter({
    history: createWebHashHistory(),
    routes: [
        {path: '/home', component: Home},
        {path: '/about', component: About},
        {path: '/news', component: News},
    ]
})

export default router

04、习惯如下:

 

标签:About,TypeScript,vue,Vue3,component,HashHistory,import,Home,path
From: https://www.cnblogs.com/tianpan2019/p/18366316

相关文章