<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript" src="./js/vue.js"></script>
<script src="./js/vuerouter.js"></script>
</head>
<body>
<div id="app">
<router-link to="/user">User</router-link>
<router-link to="/register">Register</router-link>
<router-view></router-view>
<script>
const User = {
template: `<h1>User组件</h1>`
}
const Register = {
template: `<h1>Register组件</h1>`
}
//创建路由实例对象
const router = new VueRouter({
//所有路由规则
routes: [{
path: '/user',
component: User
}, {
path: '/register',
component: Register
}, ]
})
const vm = new Vue({
el: '#app',
data: {},
//挂在路由对象
router
})
</script>
</div>
</body>
</html>