1

I have this weird problem with VueJs2 (cli 3) version, which is that Vue automatically removes parent path from URL.

I have following routes in routes.js file

import Home from "../views/Home";
import Login from "../views/Login";

const router = [

    {
        path: '/wh',
        component: {
            template: '<router-view></router-view>'
        },
        children: [
            {
                path: "/home",
                name: "home",
                component: Home
            },
            {
                path: "/login",
                name: "login",
                component: Login
            },
        ],
    },
];

export default router;

And this is my router.js file

import Vue from "vue";
import Router from "vue-router";
import routes from './routes'

Vue.use(Router);

const router = new Router({
    mode: 'history',
    routes: routes,
    scrollBehavior(to, from, savedPosition) {
        return {x: 0, y: 0}
    }
});

My main.js where I include router

import App from "./App.vue";
import router from "./router/router";
import store from "./store/store";

new Vue({
    store,
    router,
    render: h => h(App)
}).$mount("#app");

And my vue.config.js

module.exports = {
    devServer: {
        proxy: "http://my.app.test"
    },
    outputDir: "public/assets/myApp/app/",
    filenameHashing: true,
    runtimeCompiler: true,
    productionSourceMap: true,
};

The problem is following. /wh is always missing in url param. What ever I click or do I get automatically redirected to login page /wh is missing and my app is working flawlessly. I have already tried to set publicPath: '/wh' in vue.config.js and everything was working same as now. So how to properly configure my routes so I will see /wh in my URL, before other children paths?

If you need any additional information's, please let me know and I will provide. Thank you!

2
  • Try to add in index.html in <head> section <base href="/wh/" />. I had the same issue and this helped me Commented Mar 28, 2019 at 6:31
  • Yesss, this was it! :D man, unbelievable! :D You should write an answer, so I can accept it. Thank you! Commented Mar 28, 2019 at 6:42

1 Answer 1

2

Add in index.html in <head> section <base href="/wh/" />

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.