【问题标题】:make routes for a subdir in vue3为 vue3 中的子目录创建路由
【发布时间】:2021-12-02 05:33:53
【问题描述】:

我使用Vue Starter Template

Vite + Vue 3 + Tailwind CSS (starter) ⚡

应用程序应该在子目录中运行,例如:domain.com/VueApp,我按照manpage of router vuejs 添加base,如下所示:

const router = createRouter({
    history: createWebHistory(),
    base: '/VueApp/',
    routes,
})

<router-links> 仍然忽略该基本条目。

【问题讨论】:

    标签: vue.js vue-router subdirectory


    【解决方案1】:

    我不知道我是否理解正确,但如果您希望网址中包含/VueApp/,则需要将其更改为createWebHistory()。像这样:

    const router = createRouter({
        history: createWebHistory('/VueApp/'),
        base: '/VueApp/',
        routes,
    })
    

    base 声明您的应用在域中的位置,但在没有给定路径的情况下仍然可以运行。

    【讨论】:

    • 你做了,现在可以了:-)
    猜你喜欢
    • 1970-01-01
    • 2015-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-03
    • 1970-01-01
    • 1970-01-01
    • 2023-01-07
    相关资源
    最近更新 更多