Hi guys.
Having some trouble trying to get the following working.
The flow is supposed to be like this.
Person visits the homepage. Clicks the User’s button then the navigation menu is supposed to change to contain the following links:
- Home
- Back
- User 1
- User 2
I’ve found out if i create a new navigation menu in the child template i can see the menu then, however ideally i’d just like to replace the main menu contents.
I’ve faced two problems with the different solutions i’ve tried.
Problem 1:
When switching between pages, i’m getting the contents of all the previously clicked pages all together
Problem 2:
When fetching the data and updating the routes, the navigation menu isnt being updated, however router.navigation contains the appropriate links
Aurelia complaining about the user’s page not having a router-view has made me have it both in my home page and in my home page and in the user’s page. That is causing the duplication of the content of both pages. I’m not entirely sure how to fix that since im new to aurelia and javascript in general. Most of my past work has been in very basic javascript since i mainly work in backend languages like PHP/Python. Aurelia seemed like the simplest true framework to get started with and the closest to Knockout JS which i’ve used in the past which was a breeze to work with.
Sample Code:
index.html
Hello From UserIndex
index.js
import {inject} from 'aurelia-framework';
import {HttpClient} from 'aurelia-fetch-client';
import { PLATFORM } from "aurelia-framework";
@inject(HttpClient)
export class Index {
constructor(httpClient) {
this.httpClient = httpClient;
}
getRoutes() {
this.httpClient.fetch('users')
.then(response => response.json())
.then(data => {
data.forEach(item => {
console.log(item);
this.router.addRoute({ nav: true, route: 'users/:id', name: 'user', moduleId: PLATFORM.moduleName('views/home/index'), title: item.id, href: '#id' });
});
this.router.refreshNavigation();
console.log(this.router.navigation);
});
}
configureRouter(config, router) {
this.router = router;
this.config = config;
config.mapRoute({ nav: true, route: [''], name: 'home', title: 'Home', moduleId: PLATFORM.moduleName('views/home/index')});
config.mapRoute({ nav: true, route: ['users'], name: 'users', title: 'users', moduleId: PLATFORM.moduleName('views/user/index')});
this.getRoutes();
}
}