main.js
JavaScript
x
30
30
1
import Vue from 'vue'
2
import App from './App.vue'
3
import VueRouter from 'vue-router'
4
//Components
5
import Homepage from './components/Homepage.vue'
6
import Login from './components/Login.vue'
7
import RegistrationCompany from './components/RegistrationCompany.vue'
8
9
Vue.use(VueRouter);
10
Vue.config.productionTip = false
11
12
13
const routes = [
14
{ path : '/', name :'Homepage', component : Homepage },
15
{ path : '/login', name :'login', component : Login },
16
{ path : '/registration_company', name :'RegistrationCompany', component : RegistrationCompany },
17
18
]
19
20
const router = new VueRouter({
21
mode: "history",
22
routes
23
24
})
25
26
new Vue({
27
router,
28
render: h => h(App),
29
}).$mount('#app')
30
Homepage.vue
JavaScript
1
35
35
1
<template>
2
<div class="homepage">
3
<h1>Home</h1>
4
<p>
5
<router-link to="/login">Go to Login</router-link>
6
<router-link to="/registration_company">Go to Registration</router-link>
7
</p>
8
</div>
9
</template>
10
11
<script>
12
export default {
13
name: "Homepage",
14
props: {},
15
};
16
</script>
17
18
<!-- Add "scoped" attribute to limit CSS to this component only -->
19
<style scoped>
20
h3 {
21
margin: 40px 0 0;
22
}
23
ul {
24
list-style-type: none;
25
padding: 0;
26
}
27
li {
28
display: inline-block;
29
margin: 0 10px;
30
}
31
a {
32
color: #42b983;
33
}
34
</style>
35
App.js
JavaScript
1
28
28
1
<template>
2
<div id="app">
3
<Homepage />
4
</div>
5
</template>
6
7
<script>
8
import Homepage from "./components/Homepage.vue";
9
10
export default {
11
name: "App",
12
components: {
13
Homepage,
14
},
15
};
16
</script>
17
18
<style>
19
#app {
20
font-family: Avenir, Helvetica, Arial, sans-serif;
21
-webkit-font-smoothing: antialiased;
22
-moz-osx-font-smoothing: grayscale;
23
text-align: center;
24
color: #2c3e50;
25
margin-top: 60px;
26
}
27
</style>
28
Everything seems normal, it only worked once, but I don’t know what changes in the main js and it stopped working again
It is a simple code, in the main one I declared the routes, and in the home page I put the link tags to redirect to the components.
but none of this works, installation was done normally with npm
Advertisement
Answer
It seems that you are missing the router-view
JavaScript
1
11
11
1
<template>
2
<div class="homepage">
3
<h1>Home</h1>
4
<p>
5
<router-link to="/login">Go to Login</router-link>
6
<router-link to="/registration_company">Go to Registration</router-link>
7
</p>
8
<router-view />
9
</div>
10
</template>
11