We are trying to create a configurable hierarchical menu navigation for Aurelia using information stored in a database. Using as starting point the Microsoft Net Core SPA templates and generating the values from a controller. These options would not be known until run time as the database may be updated with new routes as needs to be dynamic. After compiling and running, the following error is logged when selecting a menu item. Are we trying to do something that is not allowed? Would there be a workaround?
âERROR [app-router] Error: Unable to find module with ID: app/components/counter/counterâ
Weâve not been able to include screenshots or a working VS 2017 project but can email one if any help.
[app.ts]
import { Aurelia, PLATFORM } from âaurelia-frameworkâ;
import { Router, RouterConfiguration } from âaurelia-routerâ;
import { HttpClient } from âaurelia-fetch-clientâ;
import { inject } from âaurelia-frameworkâ;
@inject(HttpClient)
export class App {
public navroutes: NavigationRoute[];
constructor(http: HttpClient) {
http.fetch(âapi/SampleData/DbRoutesâ)
.then(result => result.json() as Promise<NavigationRoute[]>)
.then(data => {
this.navroutes = data;
// Add each route (including sub route(s) here
for (var i = 0; i < data.length; i++) {
var navroute: NavigationRoute = data[i];
this.router.addRoute({
route: navroute.route,
name: navroute.name,
settings: { icon: navroute.icon },
moduleId: PLATFORM.moduleName(navroute.moduleId.toString()), // does not work (read name of module from database) - webpack can't resolve it - workaround add in constructor
//moduleId: PLATFORM.moduleName('../scheduler/scheduler'), // this works (typed name of module) - webpack can resolve it
nav: navroute.nav,
title: navroute.title
})
this.router.refreshNavigation();
}
});
router: Router
configureRouter(config: RouterConfiguration, router: Router) {
config.title = âDemoâ;
config.map([{
route: ['', 'home'],
name: 'home',
settings: { icon: 'home' },
moduleId: PLATFORM.moduleName('../home/home'),
nav: true,
title: 'Home' // The default home
}]);
this.router = router
}
}
class NavigationRoute {
id: number;
parentId: any;
route: string;
name: string;
icon: string;
moduleId: string;
nav: boolean;
title: string;
}
âŠ