Search code examples
vue.jsvue-routersubdirectory

make routes for a subdir in vue3


I use a Vue Starter Template:

Vite + Vue 3 + Tailwind CSS (starter) ⚡

The App should run in a subdirectory like: domain.com/VueApp and i followd the manpage of router vuejs to add a baselike this:

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

But the <router-links> still ignore that base entry.


Solution

  • I don´t know if I understood you correctly, but if you want the url have /VueApp/ in it, you need to change it for the createWebHistory(). Like this:

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

    base declares where your app is located at the domain, but still would run without the given path.