Skip to content

Instantly share code, notes, and snippets.

@aegenet
Last active September 2, 2022 14:46
Show Gist options
  • Save aegenet/34ca8e1c17beaeda594e4a673bd78554 to your computer and use it in GitHub Desktop.
Save aegenet/34ca8e1c17beaeda594e4a673bd78554 to your computer and use it in GitHub Desktop.
au2-router-issue
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dumber Gist</title>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1.0, user-scalable=no">
<base href="/">
</head>
<!--
Dumber Gist uses dumber bundler, the default bundle file
is /dist/entry-bundle.js.
The starting module is pointed to "main" (data-main attribute on script)
which is your src/main.ts.
-->
<body>
<my-app></my-app>
<script src="/dist/entry-bundle.js" data-main="main"></script>
</body>
</html>
{
"dependencies": {
"aurelia": "2.0.0-alpha.38"
}
}
import Aurelia from "aurelia";
import { RouterConfiguration } from '@aurelia/router';
import { MyApp } from "./my-app";
Aurelia.register(RouterConfiguration.customize({
useConfiguredRoutes: true,
})).app(MyApp).start();
<import from="./pages/missing-page"></import>
<!-- <import from="./pages/home-page"></import> -->
<div>
Menu:
<!-- <a href="/">Home</a> -->
<a load="/">Home</a>
| <a load="/page/1">Page 1</a> | <a load="/page/2">Page 2</a> | <a load="/page/3">Page 3</a>
</div>
<br>
<au-viewport name="main" fallback="missing-page"></au-viewport>
<!-- <au-viewport name="main" default="home-page" fallback="missing-page"></au-viewport> -->
import { IRouteableComponent } from "@aurelia/router";
import { NavigationInstruction } from "aurelia";
export class MyApp implements IRouteableComponent {
static routes: NavigationInstruction[] = [
{
id: "home",
path: ["", "home"],
// path: ["home"],
component: () => import("./pages/home-page"),
title: 'Home',
},
{
id: "page-1",
path: ["page/1"],
component: () => import("./pages/page-1"),
title: 'Page 1',
},
{
id: "page-2",
path: ["page/2"],
component: () => import("./pages/page-2"),
title: 'Page 2',
},
{
id: "page-3",
path: ["page/3"],
component: () => import("./pages/page-3"),
title: 'Page 3',
},
];
}
import { customElement } from "aurelia";
@customElement({
name: 'home-page',
template: `<b>Home Page</b>`
})
export class HomePage {
/** */
}
import { customElement } from "aurelia";
@customElement({
name: 'missing-page',
template: "Missing page: ${missingComponent}"
})
export class MissingPage {
public static parameters = ["id"];
public missingComponent: string;
public load(parameters: { id: string }): void {
this.missingComponent = parameters.id;
}
}
import { customElement } from "aurelia";
@customElement({
name: 'page-1',
template: `I'm a page. I'm the first one`
})
export class Page1 {
/** */
}
import { customElement } from "aurelia";
@customElement({
name: 'page-2',
template: `I'm a page. I'm the second one <a load="/page-3">click to go 3</a>`
})
export class Page2 {
/** */
}
import { customElement } from "aurelia";
@customElement({
name: 'page-3',
template: "I'm 3"
})
export class Page3 {
/** */
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment