Vue router won't maintain subdirectory url (or relative path) structure when navigating routes












0















Basically I want to deploy my dist folder (created from Vue CLI build) in to any folder I like and not worry about having to set the root or base name every time I decide to move my app. Currently I have it working to the point where I can visit the URL where I've deployed the contents of the dist folder and all is well. However, when I navigate to the app root/base (i.e /) it strips the entire current directory from the URL bar and just leaves the root domain.



EXAMPLE:



1) I can visit www.mywebsite.com/some-directory/other-directory/my-app
this all works fine and I can see my app with no errors.



2) However, when I then click a link (which are vue router based in history mode), the URL changes to www.mywebsite.com/the-link.



3) Everything still works as expected but I want to maintain the URL to be:
www.mywebsite.com/some-directory/other-directory/my-app/the-link



The only way I can get the desired result is to remove history mode from the vue router, but this then uses those ugly hash # symbols in the URL which I really don't want.



Side note: I have also set baseUrl: './' in vue.config.js otherwise my assets fail to load.



Thank you in advance.










share|improve this question

























  • I would probably just add some-directory/other-directory/ to the path of your various routes.

    – Simon Hyll
    Nov 25 '18 at 14:55











  • Thanks @SimonHyll - I've had to resort to setting baseUrl: '/my/path/' in vue.config.js for now. But I'm still interested if anyone knows a true solution. Thanks

    – Ben Clarke
    Nov 25 '18 at 22:55








  • 1





    I think the two "intended" ways for this is to either use baseUrl or to edit .htaccess, neither of which seem to be what you want

    – Simon Hyll
    Nov 27 '18 at 19:57











  • I also forgot to mention that I had to set base: '/my/path/' in the vue router config as well, along with mode: 'history'

    – Ben Clarke
    Nov 28 '18 at 12:34
















0















Basically I want to deploy my dist folder (created from Vue CLI build) in to any folder I like and not worry about having to set the root or base name every time I decide to move my app. Currently I have it working to the point where I can visit the URL where I've deployed the contents of the dist folder and all is well. However, when I navigate to the app root/base (i.e /) it strips the entire current directory from the URL bar and just leaves the root domain.



EXAMPLE:



1) I can visit www.mywebsite.com/some-directory/other-directory/my-app
this all works fine and I can see my app with no errors.



2) However, when I then click a link (which are vue router based in history mode), the URL changes to www.mywebsite.com/the-link.



3) Everything still works as expected but I want to maintain the URL to be:
www.mywebsite.com/some-directory/other-directory/my-app/the-link



The only way I can get the desired result is to remove history mode from the vue router, but this then uses those ugly hash # symbols in the URL which I really don't want.



Side note: I have also set baseUrl: './' in vue.config.js otherwise my assets fail to load.



Thank you in advance.










share|improve this question

























  • I would probably just add some-directory/other-directory/ to the path of your various routes.

    – Simon Hyll
    Nov 25 '18 at 14:55











  • Thanks @SimonHyll - I've had to resort to setting baseUrl: '/my/path/' in vue.config.js for now. But I'm still interested if anyone knows a true solution. Thanks

    – Ben Clarke
    Nov 25 '18 at 22:55








  • 1





    I think the two "intended" ways for this is to either use baseUrl or to edit .htaccess, neither of which seem to be what you want

    – Simon Hyll
    Nov 27 '18 at 19:57











  • I also forgot to mention that I had to set base: '/my/path/' in the vue router config as well, along with mode: 'history'

    – Ben Clarke
    Nov 28 '18 at 12:34














0












0








0








Basically I want to deploy my dist folder (created from Vue CLI build) in to any folder I like and not worry about having to set the root or base name every time I decide to move my app. Currently I have it working to the point where I can visit the URL where I've deployed the contents of the dist folder and all is well. However, when I navigate to the app root/base (i.e /) it strips the entire current directory from the URL bar and just leaves the root domain.



EXAMPLE:



1) I can visit www.mywebsite.com/some-directory/other-directory/my-app
this all works fine and I can see my app with no errors.



2) However, when I then click a link (which are vue router based in history mode), the URL changes to www.mywebsite.com/the-link.



3) Everything still works as expected but I want to maintain the URL to be:
www.mywebsite.com/some-directory/other-directory/my-app/the-link



The only way I can get the desired result is to remove history mode from the vue router, but this then uses those ugly hash # symbols in the URL which I really don't want.



Side note: I have also set baseUrl: './' in vue.config.js otherwise my assets fail to load.



Thank you in advance.










share|improve this question
















Basically I want to deploy my dist folder (created from Vue CLI build) in to any folder I like and not worry about having to set the root or base name every time I decide to move my app. Currently I have it working to the point where I can visit the URL where I've deployed the contents of the dist folder and all is well. However, when I navigate to the app root/base (i.e /) it strips the entire current directory from the URL bar and just leaves the root domain.



EXAMPLE:



1) I can visit www.mywebsite.com/some-directory/other-directory/my-app
this all works fine and I can see my app with no errors.



2) However, when I then click a link (which are vue router based in history mode), the URL changes to www.mywebsite.com/the-link.



3) Everything still works as expected but I want to maintain the URL to be:
www.mywebsite.com/some-directory/other-directory/my-app/the-link



The only way I can get the desired result is to remove history mode from the vue router, but this then uses those ugly hash # symbols in the URL which I really don't want.



Side note: I have also set baseUrl: './' in vue.config.js otherwise my assets fail to load.



Thank you in advance.







javascript vue.js webpack vuejs2 vue-router






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 23:48









Darkproduct

304116




304116










asked Nov 24 '18 at 23:32









Ben ClarkeBen Clarke

3452413




3452413













  • I would probably just add some-directory/other-directory/ to the path of your various routes.

    – Simon Hyll
    Nov 25 '18 at 14:55











  • Thanks @SimonHyll - I've had to resort to setting baseUrl: '/my/path/' in vue.config.js for now. But I'm still interested if anyone knows a true solution. Thanks

    – Ben Clarke
    Nov 25 '18 at 22:55








  • 1





    I think the two "intended" ways for this is to either use baseUrl or to edit .htaccess, neither of which seem to be what you want

    – Simon Hyll
    Nov 27 '18 at 19:57











  • I also forgot to mention that I had to set base: '/my/path/' in the vue router config as well, along with mode: 'history'

    – Ben Clarke
    Nov 28 '18 at 12:34



















  • I would probably just add some-directory/other-directory/ to the path of your various routes.

    – Simon Hyll
    Nov 25 '18 at 14:55











  • Thanks @SimonHyll - I've had to resort to setting baseUrl: '/my/path/' in vue.config.js for now. But I'm still interested if anyone knows a true solution. Thanks

    – Ben Clarke
    Nov 25 '18 at 22:55








  • 1





    I think the two "intended" ways for this is to either use baseUrl or to edit .htaccess, neither of which seem to be what you want

    – Simon Hyll
    Nov 27 '18 at 19:57











  • I also forgot to mention that I had to set base: '/my/path/' in the vue router config as well, along with mode: 'history'

    – Ben Clarke
    Nov 28 '18 at 12:34

















I would probably just add some-directory/other-directory/ to the path of your various routes.

– Simon Hyll
Nov 25 '18 at 14:55





I would probably just add some-directory/other-directory/ to the path of your various routes.

– Simon Hyll
Nov 25 '18 at 14:55













Thanks @SimonHyll - I've had to resort to setting baseUrl: '/my/path/' in vue.config.js for now. But I'm still interested if anyone knows a true solution. Thanks

– Ben Clarke
Nov 25 '18 at 22:55







Thanks @SimonHyll - I've had to resort to setting baseUrl: '/my/path/' in vue.config.js for now. But I'm still interested if anyone knows a true solution. Thanks

– Ben Clarke
Nov 25 '18 at 22:55






1




1





I think the two "intended" ways for this is to either use baseUrl or to edit .htaccess, neither of which seem to be what you want

– Simon Hyll
Nov 27 '18 at 19:57





I think the two "intended" ways for this is to either use baseUrl or to edit .htaccess, neither of which seem to be what you want

– Simon Hyll
Nov 27 '18 at 19:57













I also forgot to mention that I had to set base: '/my/path/' in the vue router config as well, along with mode: 'history'

– Ben Clarke
Nov 28 '18 at 12:34





I also forgot to mention that I had to set base: '/my/path/' in the vue router config as well, along with mode: 'history'

– Ben Clarke
Nov 28 '18 at 12:34












0






active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53463330%2fvue-router-wont-maintain-subdirectory-url-or-relative-path-structure-when-nav%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes
















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53463330%2fvue-router-wont-maintain-subdirectory-url-or-relative-path-structure-when-nav%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Wiesbaden

Marschland

Dieringhausen