We want to have a sidebar menu and a "main" area. Depending on how you navigate, the sidebar's menu items will change, and a new view will be loaded into the "main" area.
I've created app.html with a <router-view>
element, and a nav-bar.html that can display the main router's navigation. Let's say that I initially have "Administration" and "Reports" as routes (and therefore menu items). When a user clicks on "Administration", I'd like the menu to update to display child routes (say "Users" and "Settings") and have the admin view-model display in the app.html's <router-view>
.
Initially I tried to create a child router, but then I have to have a new <router-view>
inside of admin.html (the page won't even load without this). Instead, I want the admin.html view to display inside the <router-view>
of app.html, and for the child routes to replace the "main" routes in the nav-bar menu.
In app.js I have the following router config:
this.router.configure((config) => {
config.title = "Welcome";
config.map([
{ route: "", moduleId: "welcom", nav: false, title: "Welcome" },
{ route: "reports", moduleId: "reports", nav: true, title: "Reports" },
{ route: "admin", moduleId: "users", nav: true, title: "Administration" },
]);
});
In users.js, I have this code:
this.router.configure((config) => {
config.title = "Users";
config.map([
{ route: "", moduleId: "users", nav: true, title: "Users" },
{ route: "settings", moduleId: "settings", nav: true, title: "Settings" },
]);
});
Initially, the menu should be:
- Administration
- Reports
and "welcome.html" should be the view in the <router-view>
(the default route is 'welcome').
When the user clicks (navigates to) "Administration", the menu should refresh to be:
- Users
- Settings
with "users.html" in the <router-view>
.
However, in order to get this to work at all I need to have a further <router-view>
in "users.html" and that's not really what I want (I want the view to load in the app.html's <router-view>
).
Is there a way to achieve this in Aurelia? I've even tried injecting the parent router into the Admin constructor (using Parent.of(router)
binding) and then router.addRoute()
. The route gets added, but the menu doesn't update (even though it's data bound).
Administration
, how would you like them to get back to the initial menu set? – Mike Graham