Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how do i set dynamic base url in vuejs app?

I want develop an app with vuejs and php. That can be installed in many directory, like

https://example.com/path1/app,
https://example2.com/path1/p/app,

I don't want to compile vuejs app for each sub path. I have search a lot, but I can't find any solution on this.

How do I set vue js public path dynamically in vuejs 2? I am using @vue/cli 4.0.5 version. I have also tried using

<base href="mybase path"/> // it works for my angular app

Please advice me how could do this dynamically?

Please help

like image 990
Sarwar Hasan Avatar asked Nov 02 '19 09:11

Sarwar Hasan


People also ask

What is Base_url in Vue?

BASE_URL is not arbitrary. (doc) BASE_URL - this corresponds to the publicPath option in vue. config. js and is the base path your app is deployed at.

Is Vuejs MVVM or MVC?

js is an open-source model-view-view model (MVVM) JavaScript framework.


2 Answers

I got my answer, just need to put a public path to .

 //in vue.config.js file

 module.exports = {
     ...
     ...
     publicPath:process.env.NODE_ENV === 'production'? '.': '/'         
 }

thank you all

like image 115
Sarwar Hasan Avatar answered Oct 26 '22 19:10

Sarwar Hasan


in your app.js file, write like this:

const router = new VueRouter({
    mode: 'history',
    routes,
    base: '/base_url_name'
})
like image 24
SAKIB Avatar answered Oct 26 '22 18:10

SAKIB