Pinia+Router学习笔记(六)

简介: 从本节开始进入Router学习,先介绍下Vue-Router的基本配置
安装:pnpm add vue-router

在src目录下新建一个router文件夹,再在其中建立一个index.ts文件,里面存储路由的配置信息

import { createRouter, createWebHashHistory, RouteRecordRaw } from 'vue-router'

const routes: Array<RouteRecordRaw> = [
    {
        path: '/',
        component: () => import('../components/login.vue'),
    },
    {
        path: '/reg',
        component: () => import('../components/reg.vue'),
    },
]

const router = createRouter({
    history: createWebHashHistory(),
    routes,
})

export default router

创建完毕后在main.ts中注册:

import { createApp, toRaw } from 'vue'
import router from './router'
import App from './App.vue'

const app = createApp(App)

app.use(router)

app.mount('#app')

接下来在任意一个组件中定义出口即可,这里使用的是App.vue

<template>
    <h1>小满最骚</h1>
    <router-link to="/reg">点击此处跳转</router-link>
    // 路由出口
    <router-view></router-view>
</template>

<script setup lang='ts'>
import { ref,reactive } from 'vue'

</script>

<style scoped>

</style>
相关文章
|
9月前
|
缓存 JavaScript
Vue Router 学习 new Router
Vue Router 学习 new Router
85 0
|
1月前
|
缓存 移动开发 JavaScript
【学习笔记】Vue Router
【学习笔记】Vue Router
36 0
|
1月前
|
存储 资源调度 前端开发
React Router v6 完全指南(上)
React Router v6 完全指南(上)
193 0
|
移动开发 JavaScript 前端开发
React-Router
React-Router
54 0
|
前端开发 中间件 SEO
Pinia+Router学习笔记(七)
本节介绍Vue-Router的两种路由模式
68 0
|
网络架构
Pinia+Router学习笔记(十)
本节记录Vue-Router的两种路由传参方式
140 0
|
前端开发
Pinia+Router学习笔记(四)
本节记录Pinia中Action和Getters相关知识点
108 0
|
API
Pinia+Router学习笔记(五)
本节记录例API和Pinia持久化插件相关内容
68 0
|
JavaScript
Pinia+Router学习笔记(二)
本节记录修改State中值的五种方式
71 0
|
JavaScript
Pinia+Router学习笔记(一)
本系列笔记内容根据B站up主“小满zs”视频教程整理而成,本节记录pinia的搭建过程
122 0

热门文章

最新文章