后台返回来的路径名不合理,但多个项目在使用中了,不方便改时可以使用别名。可以有多个或一个。
First.vue
<template>
<h1>First Seciton</h1>
</template>
Second.vue,Third.vue代码同理
UserSettings.vue
<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
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文章来源:https://www.toymoban.com/news/detail-650881.html
<template>
<h1>Nested Named Views</h1>
<hr>
<router-view></router-view>
<hr>
</template>
<script setup lang="ts">
</script>
<style scoped></style>
文章来源地址https://www.toymoban.com/news/detail-650881.html
到了这里,关于【Vue-Router】别名的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!