handleNavigationAction method
Implementation
Future<void> handleNavigationAction(String? sourceUrl, String targetUrl, WebFNavigationType navigationType) async {
WebFNavigationAction action = WebFNavigationAction(sourceUrl, targetUrl, navigationType);
WebFNavigationDelegate delegate = navigationDelegate!;
try {
WebFNavigationActionPolicy policy = await delegate.dispatchDecisionHandler(action);
if (policy == WebFNavigationActionPolicy.cancel) return;
String targetPath = action.target;
if (!Uri.parse(targetPath).isAbsolute) {
String base = rootController.url;
targetPath = rootController.uriParser!.resolve(Uri.parse(base), Uri.parse(targetPath)).toString();
}
if (action.target.trim().startsWith('#')) {
String oldUrl = rootController.url;
HistoryModule historyModule = rootController.module.moduleManager.getModule('History')!;
historyModule.pushState(null, url: targetPath);
await window.dispatchEvent(HashChangeEvent(newUrl: targetPath, oldUrl: oldUrl));
return;
}
switch (action.navigationType) {
case WebFNavigationType.navigate:
await rootController
.load(rootController.getPreloadBundleFromUrl(targetPath) ?? WebFBundle.fromUrl(targetPath));
break;
case WebFNavigationType.reload:
await rootController.reload();
break;
default:
// Navigate and other type, do nothing.
}
} catch (e, stack) {
if (delegate.errorHandler != null) {
delegate.errorHandler!(e, stack);
} else {
widgetLogger.warning('WebF navigation failed', e, stack);
}
}
}