When the user first launches my Aurelia web app, I need to check localStorage to see if my app needs to restore its last state. If it does, it needs to set internal model values from localStorage and restore the route. If not, it just needs to set the route to the initial route (called 'game'). So I figured I could set up my router config in app.js like this:
config.map([
{ route: '', name: 'launcher', moduleId: 'launcher'},
{ route: 'game', name: 'game', moduleId: 'game-view'},
......
Where the launcher module will do this initialization.
launcher.js (partial pseudocode):
import {
inject,
noView
} from "aurelia-framework";
import {
Router
} from 'aurelia-router';
@noView
@inject(Router)
export class Launcher {
constructor(router) {
Get localStorage values, including lastState;
if (need to restore the past state) {
router.navigateToRoute(lastState);
} else {
router.navigateToRoute('game');
}
}
}
The issue is, I really don't need a view for this module, but if I don't have a launcher.html file, Aurelia throws an error (even though everything works okay). I figured the noView decorator would do the trick, but it didn't.
Is there a way to have a navigable module without a view? Is there a better way to do this?