i've got problem when iry to split view between login page and dashboard, here's my code
MainApp.vue
<template>
<div class="main-wrapper">
<div class="navbar-bg"></div>
<TopNav />
<SideBar />
<div class="main-content">
<router-view></router-view>
</div>
<Footer />
</div>
</template>
<script>
import TopNav from "./partials/TopNav";
import SideBar from "./partials/SideBar";
import Footer from "./partials/Footer";
export default {
name: "MainApp",
components: {
TopNav,
SideBar,
Footer
}
};
</script>
Router.js
import Vue from 'vue';
import VueRouter from 'vue-router';
import Dashboard from '../components/Dashboard';
import Post from '../components/Post';
import Login from '../view/Login';
Vue.use(VueRouter);
const router = new VueRouter({
mode: 'history',
routes: [
{
title: 'Login Page',
path: '/back/login',
name: 'login',
component : Login
},
{
title: 'Dashboard',
path: '/',
name: 'dashboard',
component: Dashboard
},
{
path: '/post',
name: 'post',
component: Post
},
]
});
export default router;
app.js
import Vue from 'vue';
import Vuex from 'vuex';
import Router from './router'
import MainApp from './layouts/MainApp.vue'
Vue.use(Vuex);
new Vue({
router: Router,
render: h => h(MainApp)
}).$mount('#app');
from these codes above, everytime i go to '/back/login' route, the login page always appear with dashboard(sidebar, topnav and footer) component and yeah i know why it happen, because it's always rendering MainApp.vue. since this is my first time making SPA app with vuejs, i still don't know what's the best way to doing this(if not SPA, it will be easy to solve this), so i tried something silly here, i added some condition like this
new Vue({
router: Router,
render: $route.name ? !== 'login' ? h => h(MainApp) : h => h(login)
}).$mount('#app');
and it gave me error "this $route is not defined", i guess it's only worked inside the component, huh ?
so i want to ask the best way to split view between login page and dashboard page