I’m using a <router-view if.bind="authenticated"></router-view>
in my app.html
. The idea here is that the app requires a login to work. If the user is not yet logged in I display a full-screen login form. The router is then only display for authenticated users.
It all works very well, except if a user log out and log in again. In this situation, because the actual page doesn’t change, there is a binding issue with the router. Basically the view doesn’t bind correctly after being attached again. Here is a minimal repro:
<!-- app.html -->
<template>
<require from="./app.css"></require>
<button click.delegate="show = !show">Hide / Show</button>
<router-view if.bind="show"></router-view>
</template>
// app.ts
import { RouterConfiguration } from 'aurelia-router';
import { PLATFORM } from 'aurelia-pal';
export class App {
public configureRouter(config: RouterConfiguration) {
config.map([
{ route: '', name: 'welcome', moduleId: PLATFORM.moduleName('welcome') },
]);
}
}
<!-- welcome.html -->
<template>
<h1>Welcome ${increment}</h1>
</template>
// welcome.ts
export class Welcome {
public increment: number = 1;
public attached() {
this.increment++;
console.log('increment', this.increment);
}
}
Here is a gif of what goes wrong. The internal increment
is incremented (see console), but not the view.
What’s wrong ? How can I fix this ?