Vue Js 2 / Vue-CLI 3 / When hosted shows empty blank page
Asked Answered
P

3

7

Vue Js app working fine in dev mode, but as I upload it on the server, it simply displays a blank page. All the resources are showing up in the developer console. I am using vue-router package.

VueJs 2 / Vue-CLI-3

Below is my App.vue

<template>
  <div id="app">
    <m-nav/>
    <router-view></router-view>  
  </div>
</template>

<script>
import Navbar from './components/Navbar.vue'

export default {
  name: 'app',
  components: {
    'm-nav':Navbar

  }
}


</script>



<style>

</style>

This is my main.js

import Vue from 'vue'
import VueRouter from 'vue-router'
import App from './App.vue'
import HomePage from './components/HomePage.vue'
import Brochure from './components/Brochure.vue'
import Register from './components/Register.vue'

Vue.config.productionTip = false

Vue.use(VueRouter);

const routes = [
    {
        path:'/',
        component: HomePage
    },
    {
        path:'/download',
        component: Brochure
    },
    {
        path:'/register',
        component: Register
    }
];

const router = new VueRouter({
    routes,
    mode: 'history'
});

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

after running npm run build, It shows a blank page, although I can see some stuff in the DOM <div id="app"></div>

http://prntscr.com/lvasvo

I am not getting, where I have made a mistake! The project is complete, but stuck on this part! :(

Plasm answered 15/12, 2018 at 13:40 Comment(1)
got same problem, and also hash mode works well without query paramTourcoing
B
2

follow this tips:

  1. use <%= BASE_URL %> for script and link tags which wrote on index.html
  2. create vue.config.js in root of project and config your public path for production and development mode like:
module.exports = {
  publicPath:
    process.env.NODE_ENV === "production" ? "/" : "/"
  }
};

just use relative path, to know more about it, read this link:

https://cli.vuejs.org/config/#publicpath

create config.vue.js

Brechtel answered 11/4, 2020 at 11:19 Comment(0)
C
1

In my case the issue was in the Router.beforeEach function that I had in index.js file inside the router folder to add a route guard. I had to rewrite it after upgrading it from Vue 2 to Vue 3 to make it work.

Copp answered 7/9, 2021 at 4:53 Comment(1)
This just saved me so much time ty, was working fine on local serving the app but moving to production w/apache app just continuously loaded with white screen.Deviationism
T
0

Just encounter the same issue with vue-cli3 project. And my main reason getting this issue is my app doesn't deploy on the root of the domain,instead on a sub-path.

There're several tricky configures:

  1. vue.config.js (it's vue-cli3 exclusive): to set publicPath:/my-app/ ;

  2. router.js (assuming your vue-router config file is this): to set base:/my-app/; And beware of the history router mode:

    location /my-app {
             alias /var/www/my-app;
             try_files $uri /index.html last;
             index index.html;
    }
    

    And beware of the different between alias and root.

    • this mode is not support relative path publicPath:./ in vue.config.js.
Tijerina answered 6/5, 2019 at 7:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.