-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {inlineView} from 'aurelia-templating'; | |
@inlineView('<template>I\'m a 3D viewer</template>') | |
export class ViewerViewModel { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') }); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {inlineView} from 'aurelia-templating'; | |
@inlineView('<template></template>') | |
export class EmptyViewModel { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {inlineView} from 'aurelia-templating'; | |
@inlineView('<template>Home Index</template>') | |
export class HomeIndex { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<template> | |
Rooms Index | |
<router-view name="default"></router-view> | |
</template> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {inlineView} from 'aurelia-templating'; | |
@inlineView('<template>I\'m a large view</template>') | |
export class LargeViewModel { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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