Skip to content

Commit

Permalink
Merge pull request #1676 from appwrite/fix-redirects
Browse files Browse the repository at this point in the history
Fix: Redirects
  • Loading branch information
TorstenDittmann authored Feb 18, 2025
2 parents 8aa34e2 + c613ab9 commit 31ad83e
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 42 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
"tslib": "^2.8.1",
"typescript": "^5.6.3",
"vite": "^5.4.11",
"vitest": "^1.6.0"
"vitest": "^1.6.1"
},
"type": "module",
"packageManager": "pnpm@9.7.0+sha512.dc09430156b427f5ecfc79888899e1c39d2d690f004be70e05230b72cb173d96839587545d09429b55ac3c429c801b4dc3c0e002f653830a420fa2dd4e3cf9cf"
Expand Down
86 changes: 48 additions & 38 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 14 additions & 3 deletions src/routes/+layout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,18 @@ export const load: LayoutLoad = async ({ depends, url, route }) => {
}
};

function withParams(pathname: string, searchParams: URLSearchParams) {
if (searchParams.size > 0) return `${pathname}?${searchParams.toString()}`;
return pathname;
function withParams(pathname: string, searchParams: URLSearchParams): string {
const redirect = searchParams.get('redirect');

if (redirect) {
const extras = new URLSearchParams(searchParams);
extras.delete('redirect');
const extraQuery = extras.toString();
const finalRedirect = extraQuery
? `${redirect}${redirect.includes('?') ? '&' : '?'}${extraQuery}`
: redirect;
return `${pathname}?redirect=${encodeURIComponent(finalRedirect)}`;
}
const query = searchParams.toString();
return query ? `${pathname}?${query}` : pathname;
}

0 comments on commit 31ad83e

Please sign in to comment.