feat: implement web URL constants and enhance navigation handling
- Introduced a centralized `WEB_URL` constant for managing application routes, improving maintainability and readability across components. - Updated various components, including login, auth, and main app modules, to utilize the new `WEB_URL` constants for navigation, ensuring consistency in route management. - Added a new `AppHomeRedirect` component to streamline user redirection based on privileges, enhancing user experience. - Implemented client-side navigation functions to prevent full page reloads, improving performance and user interaction. - Added tests for new functionalities, ensuring reliability in navigation and URL handling. These changes significantly enhance the application's routing structure and navigation efficiency, providing a more cohesive user experience.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
type ClientNavigate = (to: string, options: { replace: boolean }) => void | Promise<void>;
|
||||
|
||||
interface SessionLifecycle {
|
||||
onStart?: () => void | Promise<void>;
|
||||
onEnd?: () => void;
|
||||
}
|
||||
|
||||
let navigateFn: ClientNavigate | null = null;
|
||||
let sessionLifecycle: SessionLifecycle = {};
|
||||
|
||||
export function registerClientNavigate(fn: ClientNavigate): void {
|
||||
navigateFn = fn;
|
||||
}
|
||||
|
||||
export function registerSessionLifecycle(lifecycle: SessionLifecycle): void {
|
||||
sessionLifecycle = lifecycle;
|
||||
}
|
||||
|
||||
export function resetClientNavigate(): void {
|
||||
navigateFn = null;
|
||||
sessionLifecycle = {};
|
||||
}
|
||||
|
||||
export function notifySessionStart(): void {
|
||||
void sessionLifecycle.onStart?.();
|
||||
}
|
||||
|
||||
export function notifySessionEnd(): void {
|
||||
sessionLifecycle.onEnd?.();
|
||||
}
|
||||
|
||||
/**
|
||||
* Stay inside the already-loaded SPA when possible.
|
||||
* A full `location.replace` makes nginx look up a real file (e.g. `/auth/login`) and 404.
|
||||
*/
|
||||
export function clientReplace(to: string): void {
|
||||
if (!navigateFn) {
|
||||
window.location.replace(to);
|
||||
return;
|
||||
}
|
||||
|
||||
void Promise.resolve(navigateFn(to, { replace: true })).catch(() => {
|
||||
window.location.replace(to);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user