Skip to content

Commit db56065

Browse files
committed
Allow either route resolver instances, or components with an optional resolverClass which should accept the component and route key in its constructor.
1 parent e29ecad commit db56065

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

js/src/common/utils/mapRoutes.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,13 @@ export default function mapRoutes(routes, basePath = '') {
1616
for (const key in routes) {
1717
const route = routes[key];
1818

19-
if ('render' in route.component || 'onmatch' in route.component) {
20-
map[basePath + route.path] = route.component;
19+
if ('resolver' in route) {
20+
map[basePath + route.path] = route.resolver;
21+
} else if ('component' in route) {
22+
const resolverClass = 'resolverClass' in route ? route.resolverClass : DefaultResolver;
23+
map[basePath + route.path] = new resolverClass(route.component, key);
2124
} else {
22-
map[basePath + route.path] = new DefaultResolver(route.component, key);
25+
throw new Error(`Either a resolver or a component must be provided for the route [${key}]`);
2326
}
2427
}
2528

0 commit comments

Comments
 (0)