I have a Vue 2.0 webapplication that runs without problems on my computer, but I can't seem to get it to work on a server without the app running on the root directory.
e.g: 'www.someserver.com/my-app/
' instead of 'www.someserver.com/
'.
I used the webpack-simple template which has this basic webpack configuration. How can I make sure that the app will load the files from the folder instead of the root?
You can edit this file directly with your editor of choice to change the saved options. You can also use the vue config command to inspect or modify the global CLI config.
On file vue.config.js
module.exports = {
/* ... */
publicPath: process.env.NODE_ENV === 'production' ? '/my-app/' : '/'
}
On file router.js
/* ... */
import { publicPath } from '../vue.config'
/* ... */
export default new Router({
mode: 'history',
base: publicPath,
/* ... */
})
Assuming your server is already serving your html/js bundles when you go to the url you want.... If you are using vue-router, you also need to set the base path there.
const router = new VueRouter({
base: "/my-app/",
routes
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With