라우터 세팅하기 : npm install vue-router@4
템플릿에서 <router-link>
태그 설정하기
<router-link to="/home"> Home </router-link>
<router-link to="/servicees"> Services </router-link>
main.js
에서 Vue와 Vue 라우터 import 하고 함수를 이용해 호출하기import Vue from 'vue';
import VueRouter from 'vue-router';
Vue.use(VueRouter)
const Home = { templete:
'<div>Home</div>
}
const Services = { templete :'<div>Services</div>'
}
5.라우트를 정의합니다. 각 라우트는 반드시 컴포넌트와 매핑되어야 합니다.
const routes = [
{ path: '/home' , component: Home },
{ path: '/services' , component: Services }
]
const router = new VueRouter ({ routes })
const app = new Vue({ router }).$mount('#app')
const User = {
template:'<div>User {{ $route.params.name }}, PostId: {{ route.params.postid }}</div>'
}
const router = new VueRouter({
routes: [
{ path: '/user/:name/post/:postid', component: User }
]})