Utility to match url against routes
import { IMap } from "@b08/object-map";
import { matchRoute } from "@b08/route-matcher";const myRoutes = [
{ route: "/", action: () => openHomePage() },
{ route: "/dashboard/:userId", action: (parameters: IMap) => openDashboardPage(parameters["userId"]) }
];
function navigate(url: string): void {
const routes = findMatchingRoutes(url, myRoutes);
if(routes.length === 0) {
open(404);
return;
}
const firstRoute = routes[0];
firstRoute.route.action(firstRoute.parameters);
}
``