I use Vue.js and vue-router. The problem is that when you click the button with the to = "login" parameter, the url changes to " http: // localhost: 8080 / # / login ", however, the component does not return, but the old one remains and no errors are output to the console. Those. page appearance does not change. What could be the problem? We have created two components App.vue and login.vue. The transition is carried out from the html page, its code:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Игра Брейн-ринг</title> </head> <body> <div id="app"> </div> <script src="/dist/build.js"></script> <router-view></router-view> </body> </html> Everything works through main.js:
import Vue from 'vue'; import VueRouter from 'vue-router'; import App from './App.vue'; import Login from './login.vue'; Vue.use(VueRouter); const router = new VueRouter({ routes: [ { path: "#", component: App }, { path: "/login", component: Login } ] }); const app = new Vue({ router, render: function (createElement) { return createElement(App); } }).$mount('#app'); And the code of the two components. Component app.vue:
<template> <div id="app"> <img src="./assets/brain.png"> <h1></h1> <h2>Правила игры Брейн-ринг</h2> <ul> <li>Игра начинается с...</li> <li>Вам нужно успеть дать правильный ответ первее...</li> <li>Время на ответ 30 секунд...</li> <li>Игра Брейн-ринг заканчивается...</li> </ul> <h2>Вперед!</h2> <router-link to="/login"> <div class="wrapper"> <button v-on:click="onClick" id="submit-button"><b>Начать игру</b></button> </div></router-link> </div> </template> <script> export default { name: 'app', data() { return { msg: 'Добро пожаловать в игру Брейн-ринг' } }, methods: { onClick: function() { console.log(''); } } } </script> And the login.vue component
<template> <div id="login"> <h2>Регистрация</h2> </div> </template> <script> export default { name: 'login', data() { return { msg: 'Welcome to Your Vue.js App' } } </script> <style> </style> To create a project, I used the webpack-simple CLI template.