Skip to content

Instantly share code, notes, and snippets.

@euglv
Created May 22, 2019 16:43
Show Gist options
  • Save euglv/4fde41f2bba1c2fd1914e09baad02a08 to your computer and use it in GitHub Desktop.
Save euglv/4fde41f2bba1c2fd1914e09baad02a08 to your computer and use it in GitHub Desktop.
Aurelia Gist
<template>
<h1>${message}</h1>
<router-view></router-view>
</template>
export class App {
message = 'Hello World!';
configureRouter(config, router) {
const homeStratagy = (instruction) => {
if (instruction.queryParams.key) {
instruction.config.moduleId = 'search';
} else {
instruction.config.moduleId = 'landing';
}
if (instruction.config.viewPorts)
instruction.config.viewPorts.default.moduleId = instruction.config.moduleId;
console.log('homeStratagy:', instruction);
};
config.map([
{route: '', name: 'home', navigationStrategy: homeStratagy}
]);
this.router = router;
}
/*determineActivationStrategy(params, routeConfig, navigationInstruction){
console.log('determineActivationStrategy:', {params, routeConfig, navigationInstruction});
return 'invoke-lifecycle';
} /**/
}
<!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>
Landing!
<br>
<button click.trigger="goto()">Show dynamic page with random key</button><br>
</template>
import { inject } from 'aurelia-framework';
import { Router } from 'aurelia-router';
@inject(Router)
export class Landing {
constructor(router) {
this.router = router;
}
activate(params) {
this.params = params;
console.log("Landing activate:", params);
}
goto(){
this.router.navigateToRoute('home', {key: Math.random()});
}
}
<template>
Search!<br>
Key: ${params.key}<br>
<button click.trigger="home()">Go home</button>
</template>
import { inject } from 'aurelia-framework';
import { Router } from 'aurelia-router';
@inject(Router)
export class Search {
params = {};
constructor(router) {
this.router = router;
}
activate(params) {
this.params = params;
console.log("Search activate:", params);
}
home(){
this.router.navigateToRoute('home');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment