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

/ 54,526评论 / 667727阅读 / 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. RandallGuesE说道:

    tamoxifen skin changes: tamoxifen hormone therapy – where can i buy nolvadex

  2. RonaldSwobe说道:

    http://cytotec.club/# buy cytotec pills

  3. WilliamRen说道:

    http://cytotec.club/# buy cytotec online fast delivery

  4. Davidfrify说道:

    cost of propecia price get propecia pills propecia generics

  5. Davidfrify说道:

    order cheap propecia without prescription buying generic propecia buy propecia without prescription

  6. RandallGuesE说道:

    lexapro and tamoxifen: tamoxifen vs raloxifene – tamoxifen bone density

  7. Davidfrify说道:

    tamoxifen menopause tamoxifen tamoxifen hair loss

  8. WilliamRen说道:

    http://nolvadex.life/# tamoxifen brand name

  9. Davidfrify说道:

    lisinopril 10 mg daily buy zestril online lisinopril 10

  10. WilliamRen说道:

    https://lisinopril.network/# zestril medication

  11. RandallGuesE说道:

    Abortion pills online: cytotec pills online – buy cytotec

  12. RandallGuesE说道:

    cost of generic lisinopril: price of zestril – buy 20mg lisinopril

  13. RonaldSwobe说道:

    https://finasteride.store/# buy generic propecia without insurance

  14. WilliamRen说道:

    https://lisinopril.network/# lisinopril 20 mg coupon

发表回复

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