Web前端vue必做笔记之一:路由基础-页面跳转
首先我们一定要在main.js中引入router.js
import { createApp } from "vue";
import App from "./App.vue";
import router from './router.js'
const app = createApp(App)
app.use(router);
app.mount("#app");
<template>
<div>
<router-link to="/home">首页</router-link> |
<router-link to="/blog">博客</router-link>
<router-view></router-view>
</div>
</template>
<script>
export default {
}
</script>
import {createRouter, createWebHashHistory} from 'vue-router'
import Home from './components/Home'
import Blog from './components/Blog'
const router = createRouter({
history:createWebHashHistory(),
router:[
{
path:'/',
component:Home
},
{
path:'/blog',
component:Blog
}
]
})
export default router
|