[vue/vite/router]在vscode中给vite项目安装路由router/配置文件路由

/ 56,138评论 / 692980阅读 / 9点赞

安装router

import { createRouter, createWebHistory } from "vue-router"

const router = createRouter({
    routes: [],
    history: createWebHistory()
})

export default router

修改main.js

import { createApp } from 'vue'
import App from './App.vue'
import router from "./modules/router"

const app = createApp(App)

app.use(router)
app.mount('#app')

创建pages

<template>
    <router-view></router-view>
</template>

在router.js中配置页面

        {
            name:"主页",
            component: () => import('../pages/home.vue')
        },
        {
            name:"欢迎",
            path:"/hello",
            component: () => import('../pages/hello.vue')
        }
import { createRouter, createWebHistory } from "vue-router"

const router = createRouter({
    routes: [
        {
            name:"主页",
            component: () => import('../pages/home.vue')
        },
        {
            name:"欢迎",
            path:"/hello",
            component: () => import('../pages/hello.vue')
        }
    ],
    history: createWebHistory()
})

export default router

配置文件路由

当我们增加页面时,总要在router中配置一下,一旦页面多起来就很麻烦,所以可以安装文件路由,也就是以文件夹pages内的文件结构自动作为访问路径。

import Pages from "vite-plugin-pages"

export default defineConfig({
    plugins:[

        //...
        Pages(),
    ]
})
import { createRouter, createWebHistory } from "vue-router"
import routes from "~pages";

const router = createRouter({
    routes,
    history: createWebHistory()
})

export default router
  1. Jamesexite说道:

    Generic Viagra online: Viagra generic over the counter – order viagra

  2. Elmersoalf说道:

    Generic Tadalafil 20mg price Generic Tadalafil 20mg price Cialis 20mg price in USA

  3. Charlesvox说道:

    https://kamagra.win/# Kamagra Oral Jelly

  4. Charlesvox说道:

    http://levitrav.store/# Buy Vardenafil 20mg online

  5. Jamesexite说道:

    Buy Tadalafil 10mg: Generic Cialis without a doctor prescription – Buy Tadalafil 5mg

  6. WilliamPyday说道:

    Воздушные компрессоры https://kompressorgaz.ru/ купить по самым низким ценам только у нас с гарантией и бесплатной доставкой. Широкий ассортимент воздушных поршневых компрессоров.

  7. Jamesexite说道:

    Cialis over the counter: cialist.pro – buy cialis pill

  8. Charlesvox说道:

    http://kamagra.win/# Kamagra 100mg price

  9. DavidBiolo说道:

    http://cenforce.pro/# cenforce for sale

  10. Elmersoalf说道:

    generic sildenafil Buy Viagra online cheap Viagra generic over the counter

  11. Georgefrege说道:

    п»їcialis generic: Generic Tadalafil 20mg price – Generic Cialis without a doctor prescription

  12. Georgefrege说道:

    Cialis 20mg price in USA: buy cialis overseas – Buy Cialis online

  13. MartinBam说道:

    Воздушные компрессоры https://porshkompressor.ru/ в Москве – купить по низким ценам в интернет-магазине. Широкий ассортимент воздушных поршневых компрессоров. В каталоге – передвижные, стационарные модели, с прямым и ременным приводом, сухого сжатия и маслозаполненные.

  14. DavidBiolo说道:

    http://cenforce.pro/# cenforce for sale

  15. Jamesexite说道:

    Buy Viagra online cheap: Viagra without a doctor prescription Canada – cheapest viagra

  16. Charlesvox说道:

    http://kamagra.win/# Kamagra 100mg price

  17. Elmersoalf说道:

    Levitra 20 mg for sale Buy generic Levitra online Levitra 10 mg best price

  18. Charlesvox说道:

    http://cialist.pro/# buy cialis pill

  19. DavidBiolo说道:

    https://viagras.online/# viagra canada

  20. Charlesvox说道:

    http://cialist.pro/# Tadalafil price

  21. Tylerreunk说道:

    https://cenforce.pro/# Purchase Cenforce Online

  22. Jamesexite说道:

    Cialis 20mg price: Cialis 20mg price in USA – Cialis 20mg price in USA

  23. Jamesexite说道:

    cenforce.pro: Buy Cenforce 100mg Online – cheapest cenforce

  24. Tylerreunk说道:

    http://levitrav.store/# Levitra 10 mg best price

  25. Elmersoalf说道:

    buy Viagra over the counter Buy Viagra online cheap sildenafil over the counter

  26. chistka_oiEi说道:

    лазерный очиститель цена http://www.apparaty-lazernoy-ochistki.ru .

  27. Tylerreunk说道:

    https://viagras.online/# Sildenafil Citrate Tablets 100mg

  28. Georgefrege说道:

    cenforce for sale: Purchase Cenforce Online – cenforce for sale

  29. KerrySharl说道:

    Компрессоры воздушные https://kompressorpnevmo.ru/ купить в Москве по лучшей цене. Широкий выбор брендов. Доставка по всей РФ. Скидки, подарки, гарантия от магазина.

  30. Davidfrify说道:

    zestoretic 20-25 mg lisinopril generic lisinopril 2.5 mg buy online

回复 chistka_oiEi 取消回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注