Browse Source

BI-86090 history提供检测路由是否已存在的get方法

es6
windy 4 years ago
parent
commit
f915fab6a8
  1. 11
      src/router/router.js
  2. 2
      typescript/router/router.ts

11
src/router/router.js

@ -498,6 +498,17 @@
this.handlers.unshift({route: route, callback: callback}); this.handlers.unshift({route: route, callback: callback});
}, },
// check route is Exist. if exist, return the route
checkRoute: function (route) {
for (var i = 0; i < this.handlers.length; i++) {
if (this.handlers[i].route.toString() === Router.prototype._routeToRegExp(route).toString()) {
return this.handlers[i];
}
}
return null;
},
// remove a route match in routes // remove a route match in routes
unRoute: function (route) { unRoute: function (route) {
var index = _.findIndex(this.handlers, function (handler) { var index = _.findIndex(this.handlers, function (handler) {

2
typescript/router/router.ts

@ -26,6 +26,8 @@ export declare class History {
route(route: string, callback: Function): void; route(route: string, callback: Function): void;
checkRoute(route: string): { route: string, callback: Function};
unRoute(route: string): void; unRoute(route: string): void;
checkUrl(e?: Event): void; checkUrl(e?: Event): void;

Loading…
Cancel
Save