diff --git a/src/app/infrastructure/router/router.ts b/src/app/infrastructure/router/router.ts index 19e4eaf..a5f9d84 100644 --- a/src/app/infrastructure/router/router.ts +++ b/src/app/infrastructure/router/router.ts @@ -9,10 +9,14 @@ class Router { ) {} /** - * Router navigation method - * @returns Promise + * Initializes the router by adding event listeners and rendering the initial module. */ - async navigate(): Promise { + init(): void { + window.addEventListener("popstate", () => this.navigate()); + document.addEventListener("DOMContentLoaded", () => this.navigate()); + } + + private async navigate(): Promise { try { const currentPath = this.getSanitizedPath(window.location.pathname); const matchedRoute = await this.findMatchingRoute( diff --git a/src/app/main.ts b/src/app/main.ts index 81b934f..f61bbe0 100644 --- a/src/app/main.ts +++ b/src/app/main.ts @@ -3,6 +3,4 @@ import { routesConfig } from "./routes"; const rootElement = document.getElementById("root")!; const router = new Router(routesConfig, rootElement); - -window.addEventListener("popstate", () => router.navigate()); -document.addEventListener("DOMContentLoaded", () => router.navigate()); +router.init();