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

/ 47,453评论 / 494074阅读 / 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. Lakuqt说道:

    buy zithromax generic order omnacortil generic where to buy gabapentin without a prescription

  2. TracyFoome说道:

    viagra online consegna rapida: sildenafil 100mg prezzo – viagra naturale

  3. Terryflodo说道:

    alternativa al viagra senza ricetta in farmacia viagra prezzo pillole per erezione immediata

  4. TracyFoome说道:

    acquistare farmaci senza ricetta: farmacia online miglior prezzo – farmacie online autorizzate elenco

  5. TracyFoome说道:

    comprare farmaci online con ricetta: Tadalafil prezzo – farmacia online senza ricetta

  6. TracyFoome说道:

    farmacia online miglior prezzo: kamagra oral jelly – farmacie online sicure

  7. Sonnynap说道:

    farmacia online migliore: Tadalafil prezzo – comprare farmaci online all’estero

  8. TracyFoome说道:

    acquistare farmaci senza ricetta: cialis generico consegna 48 ore – farmacie online affidabili

  9. SidneyFub说道:

    http://tadalafilit.store/# migliori farmacie online 2023

  10. TracyFoome说道:

    farmacia online più conveniente: avanafil prezzo – farmacie online sicure

  11. Terryflodo说道:

    farmacia online senza ricetta kamagra gel prezzo farmacie online autorizzate elenco

发表回复

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