Skip to content

Commit

Permalink
Merge pull request #585 from belong112/bugfix/issue563
Browse files Browse the repository at this point in the history
fix(ProfilePage): redirect to new user profile URL after user changing slug
  • Loading branch information
MrOrz authored Dec 9, 2024
2 parents 111cc23 + 4c3de95 commit 419a0d0
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions components/ProfilePage/ProfilePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,16 @@ function ProfilePage({ id, slug }) {
//
const router = useRouter();
const latestSlug = data?.GetUser?.slug; // slug may update after user edits
const userId = currentUser?.id;
useEffect(() => {
if (!latestSlug) return;
const targetPath = `/user/${encodeURI(latestSlug)}`;
if (window.location.pathname !== targetPath) {
if (latestSlug === undefined) return;
const targetPath = latestSlug
? `/user/${encodeURI(latestSlug)}`
: `/user?id=${userId}`;
if (router.asPath !== targetPath) {
router.replace(targetPath);
}
}, [latestSlug, router]);
}, [latestSlug, userId, router]);

if (loading) {
return (
Expand Down

0 comments on commit 419a0d0

Please sign in to comment.