fix: sageOnLogin skips dashboard load when Router has saved route
Added sageOnLogin(dashboardUrl) function that checks if the SPA Router has a route (via Router.current() or URL ?page= param) before loading the dashboard. This prevents user_logined event from overwriting Router-restored content on page refresh with deep links.
This commit is contained in:
parent
97ca142092
commit
0d62b568e2
@ -132,6 +132,35 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Called by user_logined event — skip dashboard if Router has a saved route
|
||||||
|
window.sageOnLogin = async function(dashboardUrl) {
|
||||||
|
var target = bricks.getWidgetById('sage_main_content', bricks.app);
|
||||||
|
if (!target) return;
|
||||||
|
|
||||||
|
var hasRoute = false;
|
||||||
|
if (bricks.Router && bricks.Router._enabled) {
|
||||||
|
hasRoute = bricks.Router.current('sage_main_content')
|
||||||
|
|| new URLSearchParams(window.location.search).has('page');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasRoute) {
|
||||||
|
console.log('[Shell] Router has route, skip dashboard load');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// No route — load dashboard via Router
|
||||||
|
if (dashboardUrl && bricks.Router && bricks.Router._enabled) {
|
||||||
|
bricks.Router.navigate('sage_main_content', dashboardUrl);
|
||||||
|
} else if (dashboardUrl) {
|
||||||
|
var desc = { widgettype: 'urlwidget', options: { url: dashboardUrl } };
|
||||||
|
var w = await bricks.widgetBuild(desc, bricks.app);
|
||||||
|
if (w) {
|
||||||
|
target.clear_widgets();
|
||||||
|
target.add_widget(w);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// Reload global menu after login/logout
|
// Reload global menu after login/logout
|
||||||
window.sageReloadMenu = async function() {
|
window.sageReloadMenu = async function() {
|
||||||
if (typeof bricks === 'undefined') return;
|
if (typeof bricks === 'undefined') return;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user