超详细!!!electron-vite-vue开发桌面应用之配置路由router(五)

云风网
云风笔记
云风知识库

一、安装依赖

javascript 复制代码
npm install vue-router

二、配置项目文件路径

三、配置路由router

在src下新建一个router目录,然后在里面添加一个index.ts文件,在里面配置路由

javascript 复制代码
import { createRouter, createWebHashHistory  } from 'vue-router'

const router = createRouter({
  //  hash 模式。
  history: createWebHashHistory (),
  routes: [
    // 设置首页
    {
        path: '/',
        component: () => import('@/views/index.vue')
    },
    { 
        path: '/userManage', // 配置用户管理
        component: () => import('@/views/userManage/index.vue') 
    },
    { 
        path: '/noteManage', // 配置语录管理
        component: () => import('@/views/noteManage/index.vue') 
    }
  ],
})

export default router

在src下的main.ts中引入路由

javascript 复制代码
import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'
const app = createApp(App)
// 配置路由
app.use(router)
app.mount('#app').$nextTick(() => {
  // Use contextBridge
  window.ipcRenderer.on('main-process-message', (_event, message) => {
    console.log(message)
  })
})

在App.vue中使用路由

javascript 复制代码
<template>
  <router-view></router-view>
</template>

四、运行项目效果如下

点击标签相互路由跳转



相关推荐
XTTX11020 小时前
Vue3+Cesium教程(36)--动态设置降雨效果
前端·javascript·vue.js
han_1 天前
从一道前端面试题,谈 JS 对象存储特点和运算符执行顺序
前端·javascript·面试
前端小超超1 天前
ionic + vue3 + capacitor遇到backButton问题
前端·javascript·vue.js
EndingCoder1 天前
枚举类型:常量集合的优雅管理
前端·javascript·typescript
起名时在学Aiifox1 天前
从零实现前端数据格式化工具:以船员经验数据展示为例
前端·vue.js·typescript·es6
cute_ming1 天前
关于基于nodeMap重构DOM的最佳实践
java·javascript·重构
码途潇潇1 天前
JavaScript 中 ==、===、Object.is 以及 null、undefined、undeclared 的区别
前端·javascript
放牛的小伙1 天前
vue 表格 vxe-table 加载数据的几种方式,更新数据的用法
vue.js
Sun_小杰杰哇1 天前
Dayjs常用操作使用
开发语言·前端·javascript·typescript·vue·reactjs·anti-design-vue
basestone1 天前
🚀 从重复 CRUD 到工程化封装:我是如何设计 useTableList 统一列表逻辑的
javascript·react.js·ant design