i am learning Relative redirecting from Vue router Doc.
and i am tring to implement the doc example of the code.
const routes = [
{
// will always redirect /users/123/posts to /users/123/profile
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'
},
},
]
in my realize of the code .
it says when the link path is /users/123/posts
the finally redirect path will be /users/123/profile not /profile.
So the same url of my code path :
http://localhost:5173/maxroll-build/S/roll >> http://localhost:5173/maxroll-build/S/roll
but the real path finally is http://localhost:5173/gg
I tried my way for a long time. Among them, I found a question that was almost exactly the same as mine (Relative redirecting bug #1902).
but i am still not totally realize how to write a Relative redirecting. is there any code demo?
or maybe the Doc still ambiguity ?
my code:
// router/index.js
const routes = [
// ... other route
{
path: "/maxroll-build/:buildLevel/roll",
redirect: (to) => {
console.log("to ", to);
// console of to.fullPath: "/maxroll-build/S/roll"
return { path: "gg" }; // here finally web link: http://localhost:5173/gg
},
},
{
path: "/maxroll-build/:buildLevel/gg",
component: MaxRollLevel,
},
// ... other route
];
leo41271 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.