@sierra-95/svelte-scaffold 1.2.10 → 1.2.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Hooks/redirectTo.d.ts +7 -0
- package/dist/Hooks/redirectTo.js +33 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function buildRedirectUrl(baseUrl: string, redirectTo?: string): string;
|
|
2
|
+
type RedirectOptions = {
|
|
3
|
+
replaceState?: boolean;
|
|
4
|
+
useHardRedirect?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export declare function handleRedirect(baseUrl: string, redirectTo?: string, options?: RedirectOptions): void;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { addToast } from '../index.js';
|
|
2
|
+
import { goto } from '$app/navigation';
|
|
3
|
+
import { browser } from '$app/environment';
|
|
4
|
+
function sanitizeRedirect(redirectTo) {
|
|
5
|
+
if (!redirectTo)
|
|
6
|
+
return undefined;
|
|
7
|
+
if (!redirectTo.startsWith('/')) {
|
|
8
|
+
addToast({
|
|
9
|
+
status: 'warning',
|
|
10
|
+
message: `Invalid redirectTo path: "${redirectTo}". It must start with a "/". Redirect will be ignored.`,
|
|
11
|
+
persistent: true
|
|
12
|
+
});
|
|
13
|
+
return undefined;
|
|
14
|
+
}
|
|
15
|
+
return redirectTo;
|
|
16
|
+
}
|
|
17
|
+
export function buildRedirectUrl(baseUrl, redirectTo) {
|
|
18
|
+
const safe = sanitizeRedirect(redirectTo);
|
|
19
|
+
return safe
|
|
20
|
+
? `${baseUrl}?redirectTo=${encodeURIComponent(safe)}`
|
|
21
|
+
: baseUrl;
|
|
22
|
+
}
|
|
23
|
+
export function handleRedirect(baseUrl, redirectTo, options = {}) {
|
|
24
|
+
if (!browser)
|
|
25
|
+
return;
|
|
26
|
+
const finalUrl = buildRedirectUrl(baseUrl, redirectTo);
|
|
27
|
+
const { replaceState = false, useHardRedirect = false } = options;
|
|
28
|
+
if (useHardRedirect) {
|
|
29
|
+
window.location.href = finalUrl;
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
goto(finalUrl, { replaceState });
|
|
33
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -60,5 +60,6 @@ export { validateLayoutMenuSections, filterSectionsByRole } from './Hooks/layout
|
|
|
60
60
|
export { buttonRipple } from './Hooks/button.js';
|
|
61
61
|
export { buildSearchIndex } from './Hooks/buildSearch.js';
|
|
62
62
|
export { isValidEmail } from './Hooks/validateForms.js';
|
|
63
|
+
export { handleRedirect, buildRedirectUrl } from './Hooks/redirectTo.js';
|
|
63
64
|
export type { SearchResult } from './Hooks/buildSearch.js';
|
|
64
65
|
export type { Section, SectionItem } from './stores/modules/layout.js';
|
package/dist/index.js
CHANGED
|
@@ -72,3 +72,4 @@ export { validateLayoutMenuSections, filterSectionsByRole } from './Hooks/layout
|
|
|
72
72
|
export { buttonRipple } from './Hooks/button.js';
|
|
73
73
|
export { buildSearchIndex } from './Hooks/buildSearch.js';
|
|
74
74
|
export { isValidEmail } from './Hooks/validateForms.js';
|
|
75
|
+
export { handleRedirect, buildRedirectUrl } from './Hooks/redirectTo.js';
|