【Vue-Router】别名

后台返回来的路径名不合理,但多个项目在使用中了,不方便改时可以使用别名。可以有多个或一个。


First.vue

html 复制代码
<template>
  <h1>First Seciton</h1>
</template>

Second.vueThird.vue代码同理

UserSettings.vue

html 复制代码
<template>
  <h1>UserSettings</h1>
  <router-link to="/settings/children1">children1</router-link>
  <br />
  <router-link to="/settings/children2">children2</router-link>
  <br>
  <button @click="toBackPage">返回</button>
  <hr>
  <router-view></router-view>
  <router-view name="a"></router-view>
  <router-view name="b"></router-view>
</template> 

<script setup lang="ts">
import { useRouter } from 'vue-router';
const router = useRouter();
const toBackPage = () => {
  router.go(-1);
}
</script>

<style scoped></style>

index.ts

ts 复制代码
import { createRouter, createWebHistory } from 'vue-router'
import First from '../components/First.vue'
import Second from '../components/Second.vue'
import Third from '../components/Third.vue'
import UserSettings from '../components/UserSettings.vue'

export const router = createRouter({
  history: createWebHistory(),
  // alias 起别名,都可以访问同一页面
  alias: ['/user-settings', '/Settings'],
  routes: [
    {
      path: '/settings',
      component: UserSettings,
      children: [
        {
          path: 'children1',
          components: {
            default: First,
            a: Second,
            b: Third,
          },
        },
        {
          path: 'children2',
          components: {
            default: Third,
            a: Second,
            b: First,
          },
        },
      ]
    },

  ],
})

App.vue

html 复制代码
<template>
  <h1>Nested Named Views</h1>
  <hr>
  <router-view></router-view>
  <hr>
</template>

<script setup lang="ts">

</script>

<style scoped></style>


相关推荐
摇滚侠15 分钟前
01 基础语法 JavaScript 入门到精通全套教程
开发语言·javascript·ecmascript
云水一下38 分钟前
CSS3从零基础到精通(一):前世今生与基础入门
前端·css3
顾凌陵41 分钟前
CSRF&SSRF漏洞攻击的溯源分析与实战
前端·csrf
用户69190268133943 分钟前
JS 初了解:从“网页玩具”到企业级语言的进化
javascript
月月大王的3D日记43 分钟前
Three.js 材质篇(中):从兰伯特到PBR,一篇文章看懂五种光照材质
前端·javascript
且白44 分钟前
leaflet切片变色、地图滤镜逻辑实现 colorfilter
前端·javascript
用户887665426631 小时前
Linux 终端入门:新手必须掌握的常用命令和基本思路
前端·操作系统
丷丩1 小时前
MapLibre GL JS第30课:添加视频
javascript·音视频·gis·mapbox·maplibre gl js
techdashen1 小时前
拆开任意 Electron 应用:从 Windows 安装包到 Discord 的私有更新协议
javascript·windows·electron
用户125758524361 小时前
Vue3 后台框架的网络请求怎么设计?看 XYGo Admin 三套 Axios 实例与拦截器方案
前端