Skip to content

Commit 613368c

Browse files
authored
NavigationObserver: Fix failure in MAUI (#50)
### **Description** - Fix MAUI compatibility by checking `addEventListener` function existence - Add fallback initialization when Blazor event listener unavailable - Prevent runtime errors in environments without Blazor event support
1 parent 3c4cd59 commit 613368c

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

src/wwwroot/NavigationObserver.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,18 @@ let hasInitialized = false;
167167
ensureInitialized();
168168
}
169169

170-
if (window.Blazor) {
171-
window.Blazor.addEventListener('afterStarted', ensureInitialized);
172-
} else {
170+
const tryAddBlazorListener = () => {
171+
if (window.Blazor && typeof window.Blazor.addEventListener === "function") {
172+
window.Blazor.addEventListener('afterStarted', ensureInitialized);
173+
return true;
174+
}
175+
return false;
176+
};
177+
178+
if (!tryAddBlazorListener()) {
173179
document.addEventListener('DOMContentLoaded', () => {
174-
if (window.Blazor) {
175-
window.Blazor.addEventListener('afterStarted', ensureInitialized);
180+
if (!tryAddBlazorListener()) {
181+
ensureInitialized();
176182
}
177183
});
178184
}

0 commit comments

Comments
 (0)