日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

实例入手vue-router重定向

發布時間:2025/3/19 vue 20 豆豆
生活随笔 收集整理的這篇文章主要介紹了 实例入手vue-router重定向 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

場景

當一進來某一個APP,想讓其顯示某個頁面,所以需要在index.vue使用重定向使其重定向到初始頁面。

效果

前文

從實例入手學習Vue-router的使用-實現音樂導航菜單切換

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/84504573

知識儲備

重定向也是通過 routes 配置來完成,下面例子是從 /a 重定向到 /b:

const router = new VueRouter({routes: [{ path: '/a', redirect: '/b' }] })

重定向的目標也可以是一個命名的路由:

const router = new VueRouter({routes: [{ path: '/a', redirect: { name: 'foo' }}] })

甚至是一個方法,動態返回重定向目標:

const router = new VueRouter({routes: [{ path: '/a', redirect: to => {// 方法接收 目標路由 作為參數// return 重定向的 字符串路徑/路徑對象}}] })

實例

在router下的index.js中

import Vue from 'vue' import Router from 'vue-router' import Index from '@/pages/index' import Home from "@/pages/home" import Artists from "@/pages/artists" import ListCate from "@/pages/listcate" import Ucenter from "@/pages/ucenter" import Search from "@/pages/search" Vue.use(Router)export default new Router({routes: [{path: '/',name: 'Index',redirect:"/home",component: Index,children:[{path: 'home',component: Home},{path:"artists",component:Artists},{path:"listcate",component:ListCate},{path:"ucenter",component:Ucenter},{path:"search",component:Search}]}] })

?

總結

以上是生活随笔為你收集整理的实例入手vue-router重定向的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。