-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path24Routing.txt
89 lines (70 loc) · 2.58 KB
/
24Routing.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
Vue Routing
- Install Vue package
- Import Component
- Make Routers
- Register Router
- Test
1) Install Vue-Router
- npm install vue-router
2) Import router in main.js file
- src/main.js:
import Vue from 'vue'
import App from './App.vue'
import VueRouter from 'vue-router'; // import router
import About from './components/About' // After make a About component then after import here
import Home from './components/Home' // After make a Home component then after import here
Vue.use(VueRouter) // Use VueRouter
const routes = [ // Create routes
{
path:'/', // Given Path (Home component)
component:Home // Given Components (Home component)
},
{
path:'/about', // Given Path (About component)
component:About // Given Components (About component)
}
]
const router = new VueRouter({ // object defined for routes
routes
})
Vue.config.productionTip = false
new Vue({
router: router
render: h => h(App),
}).$mount('#app')
3) Make a two new components
- src/components/Home.vue:
<template>
<h1>Home Page</h1>
</template>
<script>
export default {
name: 'Home'
}
</script>
- src/components/About.vue:
<template>
<h1>About Page</h1>
</template>
<script>
export default {
name: 'About'
}
</script>
4) Add <router-view> in App.vue
- src/App.vue:
<template>
<div id="app">
<router-view></router-view> // add this after making a routers
</div>
</template>
<script>
export default {
name: "App",
components: {
}
};
</script>
5) Now check the URL:
- localhost:8080/#/ (Home Page)
- localhost:8080/#/about (About Page)