'vuejs2 multi-page not loading router-view
I want to create a POC for multi-page app.
I start with a basic app by doing vue create poc
then i add a second main.js named test.js with the same lines than the main.js
// main.js
import Vue from 'vue'
import App from './App.vue'
import './registerServiceWorker'
import router from './router'
import store from './store'
Vue.config.productionTip = false
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
// test.js
import Vue from 'vue'
import App from './App.vue'
import './registerServiceWorker'
import router from './router'
import store from './store'
Vue.config.productionTip = false
new Vue({
router,
store,
render: h => h(App)
}).$mount('#app')
// vue.config.js
module.exports = {
// https://cli.vuejs.org/config/#pages
pages: {
main: {
// entry for the page
entry: 'src/main.js',
// the source template
template: 'public/index.html',
// output as dist/index.html
//filename: 'index.html',
// when using title option,
// template title tag needs to be <title><%= htmlWebpackPlugin.options.title %></title>
title: 'Multi-page Main',
// chunks to include on this page, by default includes
// extracted common chunks and vendor chunks.
//chunks: ['chunk-vendors', 'chunk-common', 'index']
},
pasquier: {
// entry for the page
entry: 'src/test.js',
// the source template
template: 'public/index.html',
// output as dist/index.html
//filename: 'index.html',
// when using title option,
// template title tag needs to be <title><%= htmlWebpackPlugin.options.title %></title>
title: 'Multi-page test',
// chunks to include on this page, by default includes
// extracted common chunks and vendor chunks.
//chunks: ['chunk-vendors', 'chunk-common', 'index']
},
// when using the entry-only string format,
// template is inferred to be `public/subpage.html`
// and falls back to `public/index.html` if not found.
// Output filename is inferred to be `subpage.html`.
//subpage: 'src/subpage/main.js'
}
}
The issue is that when I open my website with the url : localhost:8080/main
I have :

I have the same exact page with localhost:8080/main
But when I load the app without the multi-page I have:

Which mean that the router-view is not loaded, but the router-link is. I didn't change any other code.
// App.vue
<template>
<div id="app">
<div id="nav">
<router-link to="/">Home</router-link> |
<router-link to="/about">About</router-link>
</div>
<router-view/>
</div>
</template>
// router/index.js
import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
Vue.use(VueRouter)
const routes = [
{
path: '/',
name: 'Home',
component: Home
},
{
path: '/about',
name: 'About',
// route level code-splitting
// this generates a separate chunk (about.[hash].js) for this route
// which is lazy-loaded when the route is visited.
component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
}
]
const router = new VueRouter({
mode: 'history',
base: process.env.BASE_URL,
routes
})
export default router
How can i charge the root page / when using the multi-page ?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
