Skip to content

Instantly share code, notes, and snippets.

@balazsmeszegeto
Forked from jdanyow/app.html
Last active April 13, 2018 04:11
Show Gist options
  • Save balazsmeszegeto/087cf483ccb4476a3c7cb8a76a49823e to your computer and use it in GitHub Desktop.
Save balazsmeszegeto/087cf483ccb4476a3c7cb8a76a49823e to your computer and use it in GitHub Desktop.
Aurelia Bug: redirect in child router (navigation strategy), when parent is using navigation strategy
import {inlineView} from 'aurelia-templating';
@inlineView('<template>I\'m a 3D viewer</template>')
export class ViewerViewModel { }
<template>
<button click.delegate="toHome()">To Home</button>
<button click.delegate="toRooms()">To Rooms</button>
Show 3D view: <input type="checkbox" checked.bind="showViewer" />
<br />
<router-view name="default"></router-view>
<router-view name="viewer"></router-view>
</template>
const viewerStrategy = (instruction: NavigationInstruction): void => {
if (hasViewer(instruction)) {
instruction.config.viewPorts.viewer = viewerViewPort;
} else {
instruction.config.viewPorts.viewer = emptyViewPort;
}
};
function hasViewer(instruction: NavigationInstruction): boolean {
return instruction.params.viewer === 'on';
}
const emptyViewPort = { moduleId: 'empty' };
const viewerViewPort = { moduleId: '3d-viewer' };
const routes = [
{
route: '',
name: 'home',
viewPorts: { default: { moduleId: 'home/index' }, viewer: emptyViewPort },
activationStrategy: 'invoke-lifecycle',
},
{
route: 'rooms', //rooms?viewer=on
name: 'rooms',
viewPorts: { default: { moduleId: 'rooms/index' }, viewer: viewerViewPort },
//navigationStrategy: viewerStrategy,
activationStrategy: 'invoke-lifecycle',
}
];
export class App {
configureRouter(config: RouterConfiguration, router: Router): void {
this.router = router;
config.map(routes);
}
toHome(): void {
this.router.navigateToRoute('home');
}
toRooms(): void {
this.router.navigateToRoute('rooms', { viewer: (this.showViewer ? 'on' : 'off') });
}
}
import {inlineView} from 'aurelia-templating';
@inlineView('<template></template>')
export class EmptyViewModel { }
import {inlineView} from 'aurelia-templating';
@inlineView('<template>Home Index</template>')
export class HomeIndex { }
<!doctype html>
<html>
<head>
<title>Aurelia</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body aurelia-app>
<h1>Loading...</h1>
<script src="https://jdanyow.github.io/rjs-bundle/node_modules/requirejs/require.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/config.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/aurelia.js"></script>
<script src="https://jdanyow.github.io/rjs-bundle/bundles/babel.js"></script>
<script>
require(['aurelia-bootstrapper']);
</script>
</body>
</html>
<template>
Rooms Index
<router-view name="default"></router-view>
</template>
const homeStrategy = instruction => {
if (window.innerWidth < 1200)
instruction.config.redirect = 'small';
else
instruction.config.redirect = 'large';
};
const routes = [
{
route: '',
name: 'home',
navigationStrategy: homeStrategy
},
{
route: 'small',
name: 'small',
moduleId: 'rooms/small',
activationStrategy: 'invoke-lifecycle',
},
{
route: 'large',
name: 'large',
moduleId: 'rooms/large',
activationStrategy: 'invoke-lifecycle',
},
];
export class RoomsIndex {
configureRouter(config: RouterConfiguration, router: Router): void {
config.map(routes);
}
}
import {inlineView} from 'aurelia-templating';
@inlineView('<template>I\'m a large view</template>')
export class LargeViewModel { }
import {inlineView} from 'aurelia-templating';
@inlineView('<template>I\'m a small view</template>')
export class SmallViewModel { }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment