fix(core): update
This commit is contained in:
parent
9b9675bd96
commit
daeaac2367
21696
package-lock.json
generated
21696
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
14
package.json
14
package.json
@ -13,16 +13,16 @@
|
||||
"format": "(gitzone format)"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@gitzone/tsbuild": "^2.0.22",
|
||||
"@gitzone/tsbundle": "^1.0.72",
|
||||
"@gitzone/tstest": "^1.0.43",
|
||||
"@pushrocks/tapbundle": "^3.2.9",
|
||||
"@types/node": "^14.0.23",
|
||||
"tslint": "^6.1.2",
|
||||
"@gitzone/tsbuild": "^2.1.26",
|
||||
"@gitzone/tsbundle": "^1.0.87",
|
||||
"@gitzone/tstest": "^1.0.57",
|
||||
"@pushrocks/tapbundle": "^3.2.14",
|
||||
"@types/node": "^16.7.13",
|
||||
"tslint": "^6.1.3",
|
||||
"tslint-config-prettier": "^1.15.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"path-to-regexp": "^6.1.0"
|
||||
"path-to-regexp": "^6.2.0"
|
||||
},
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
|
@ -8,8 +8,8 @@ tap.test('first test', async () => {
|
||||
expect(testrouter).to.be.instanceOf(smartrouter.SmartRouter);
|
||||
});
|
||||
|
||||
tap.test('should handle a route change', async (tools) => {
|
||||
const done = tools.defer();
|
||||
tap.test('should handle a route change', async (toolsArg) => {
|
||||
const done = toolsArg.defer();
|
||||
testrouter.on('/myawesomeroute/:any', async (routeInfoArg) => {
|
||||
expect(routeInfoArg.params.any).to.equal('hello');
|
||||
done.resolve();
|
||||
@ -18,8 +18,8 @@ tap.test('should handle a route change', async (tools) => {
|
||||
await done.promise;
|
||||
});
|
||||
|
||||
tap.test('should handle a route change', async (tools) => {
|
||||
const done = tools.defer();
|
||||
tap.test('should handle a route change', async (toolsArg) => {
|
||||
const done = toolsArg.defer();
|
||||
testrouter.on('/myawesomeroute2/:wow', async (routeInfoArg) => {
|
||||
expect(routeInfoArg.params.wow).to.equal('hello2');
|
||||
done.resolve();
|
||||
@ -29,4 +29,18 @@ tap.test('should handle a route change', async (tools) => {
|
||||
expect(window.location.href).to.equal('http://localhost:3007/myawesomeroute2/hello2');
|
||||
});
|
||||
|
||||
tap.test('should find a query param', async (toolsArg) => {
|
||||
const done = toolsArg.defer();
|
||||
testrouter.on('/myawesomeroute2/:wow', async (routeInfoArg) => {
|
||||
expect(routeInfoArg.params.wow).to.equal('hello2');
|
||||
expect(routeInfoArg.queryParams.aparam).to.equal('Yes');
|
||||
console.log('Here is what queryParams looks like');
|
||||
console.log(JSON.stringify(routeInfoArg.queryParams))
|
||||
done.resolve();
|
||||
});
|
||||
testrouter.pushUrl('/myawesomeroute2/hello2?aparam=Yes');
|
||||
await done.promise;
|
||||
expect(window.location.href).to.equal('http://localhost:3007/myawesomeroute2/hello2?aparam=Yes');
|
||||
})
|
||||
|
||||
tap.start();
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user