fix(core): update

This commit is contained in:
2021-09-08 21:46:21 +02:00
parent 9b9675bd96
commit daeaac2367
4 changed files with 18943 additions and 2844 deletions

View File

@ -13,6 +13,7 @@ export interface IRouteInfo {
path: string;
index: number;
params: { [key: string]: string };
queryParams: { [key: string]: string };
}
/**
@ -80,13 +81,19 @@ export class SmartRouter {
*/
async _handleRouteState() {
const currentLocation = window.location.pathname;
const urlSearchParams = new URLSearchParams(window.location.search);
// lets find all wanted routes.
const wantedRoutes = this.routes.filter((routeArg) => {
return !!routeArg.matchFunction(currentLocation);
});
for (const wantedRoute of wantedRoutes) {
const routeResult = wantedRoute.matchFunction(currentLocation);
wantedRoute.handler(routeResult.valueOf() as IRouteInfo); // not waiting here
wantedRoute.handler({
...(routeResult.valueOf() as Object),
queryParams: Object.fromEntries(urlSearchParams.entries()),
} as IRouteInfo); // not waiting here
}
}
}