While clicking the nav link vue-router is toggling only the url but not the view component, even though I don’t seem to have any error. The console shows that only the Home component is at the view, but hot the Not main component after clciking the second nav link.
// router index.js
import VueRouter from 'vue-router';
import Home from '../views/Home.vue';
import Shops from '../views/Shops.vue';
const router = VueRouter.createRouter({
history: VueRouter.createWebHashHistory(),
routes: [
{
path: '/',
name: 'Home',
component: Home,
},
{
path: '/shops',
name: 'Shops',
component: Shops,
},
],
});
export default router;
// Home view
<template>
<div class="wrapper">
<Header />
<Main />
<Footer />
</div>
</template>
<script>
import Header from '../components/Header.vue';
import Footer from '../components/Footer.vue';
import Main from '../components/Main.vue';
export default {
name: 'Home',
components: {
Header,
Footer,
Main,
},
};
</script>
<style lang="scss" scoped></style>
// anoteher view
<template>
<div class="wrapper">
<NotMain />
</div>
</template>
<script>
import NotMain from '../components/NotMain.vue';
export default {
name: 'Shops',
components: {
NotMain,
},
};
</script>
<style lang="scss" scoped></style>
2
Answers
not specified at app.js That made the trick. I needed to post the inside the app.js main component
In your app.vue only router-view part of template will change on change of route, rest all will display on every route. As checked on the stackBlitz your routes are working as expected and view changes are reflecting already.