validate that routes are an array before merging with another Router instance
This commit is contained in:
2
dist/router.js
vendored
2
dist/router.js
vendored
@ -70,6 +70,8 @@ export default class Router {
|
|||||||
}
|
}
|
||||||
use(obj) {
|
use(obj) {
|
||||||
if (obj instanceof Router) {
|
if (obj instanceof Router) {
|
||||||
|
if (!Array.isArray(obj.routes))
|
||||||
|
throw new TypeError("Routes must be an array.");
|
||||||
this.routes = [...this.routes, ...obj.routes];
|
this.routes = [...this.routes, ...obj.routes];
|
||||||
this.sortRoutes();
|
this.sortRoutes();
|
||||||
}
|
}
|
||||||
|
@ -95,6 +95,8 @@ export default class Router {
|
|||||||
*/
|
*/
|
||||||
use(obj: Router | Tpl): void {
|
use(obj: Router | Tpl): void {
|
||||||
if(obj instanceof Router) {
|
if(obj instanceof Router) {
|
||||||
|
if(!Array.isArray(obj.routes))
|
||||||
|
throw new TypeError("Routes must be an array.");
|
||||||
this.routes = [ ...this.routes, ...obj.routes ];
|
this.routes = [ ...this.routes, ...obj.routes ];
|
||||||
this.sortRoutes();
|
this.sortRoutes();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user