]> git.ipfire.org Git - thirdparty/vuejs/router.git/commitdiff
docs: fix relative redirect example (#2479)
authorskirtle <65301168+skirtles-code@users.noreply.github.com>
Mon, 17 Mar 2025 08:28:40 +0000 (08:28 +0000)
committerGitHub <noreply@github.com>
Mon, 17 Mar 2025 08:28:40 +0000 (09:28 +0100)
packages/docs/guide/essentials/redirect-and-alias.md
packages/docs/zh/guide/essentials/redirect-and-alias.md

index 5bbb87fa32489ed8f5b66474633b22278d13a652..46205283d003a7b9c4bcba52defe7f3c989d6b35 100644 (file)
@@ -54,9 +54,7 @@ const routes = [
     path: '/users/:id/posts',
     redirect: to => {
       // the function receives the target route as the argument
-      // a relative location doesn't start with `/`
-      // or { path: 'profile'}
-      return 'profile'
+      return to.path.replace(/posts$/, 'profile')
     },
   },
 ]
index aa28a0eeb94bd23335aab9fb254a96dc331fc06d..ab3a6b7cc1a54c8efbcd8769c26f0e5dcbf908a5 100644 (file)
@@ -54,9 +54,7 @@ const routes = [
     path: '/users/:id/posts',
     redirect: to => {
       // 该函数接收目标路由作为参数
-      // 相对位置不以`/`开头
-      // 或 { path: 'profile'}
-      return 'profile'
+      return to.path.replace(/posts$/, 'profile')
     },
   },
 ]