diff --git a/doc/readme.md b/doc/readme.md
index 3e189226..d3a3a4d3 100644
--- a/doc/readme.md
+++ b/doc/readme.md
@@ -14,6 +14,7 @@ owl
Observer
router
Link
+ RouteComponent
Router
store
Store
diff --git a/doc/router.md b/doc/router.md
index e9202a71..ace4fdbf 100644
--- a/doc/router.md
+++ b/doc/router.md
@@ -8,7 +8,7 @@
- [Route Definition](#route-definition)
- [Router](#router)
- [Navigation Guards](#navigation-guards)
- - [`t-routecomponent`](#t-routecomponent)
+ - [RouteComponent](#routecomponent)
- [Link](#link)
## Overview
@@ -26,8 +26,8 @@ The Owl router support the following features:
- route redirection
- navigation guards
- parameterized routes
-- a `` component
-- a `t-routecomponent` directive
+- a `` component
+- a `` component
Note that it is still in early stage of developments, and there are probably
still some issues.
@@ -148,15 +148,15 @@ async function protectRoute({ env, to }) {
A navigation guard is a function that returns a promise, which either resolves
to `true` (the navigation is accepted), or to another destination object.
-### `t-routecomponent`
+### `RouteComponent`
-The `t-routecomponent` directive directs Owl to render the component associated
+The `RouteComponent` component directs Owl to render the component associated
to the currently active route (if any):
```xml
-
+
```
diff --git a/src/index.ts b/src/index.ts
index 19444df0..28907d81 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -11,12 +11,13 @@ import { ConnectedComponent } from "./store/connected_component";
import { Store } from "./store/store";
import * as _utils from "./utils";
import { Link } from "./router/Link";
+import { RouteComponent } from "./router/RouteComponent";
import { Router } from "./router/Router";
export { Component } from "./component/component";
export { QWeb };
export const core = { EventBus, Observer };
-export const router = { Router, Link };
+export const router = { Router, RouteComponent, Link };
export const store = { Store, ConnectedComponent };
export const utils = _utils;
diff --git a/src/router/RouteComponent.ts b/src/router/RouteComponent.ts
new file mode 100644
index 00000000..164cdef1
--- /dev/null
+++ b/src/router/RouteComponent.ts
@@ -0,0 +1,27 @@
+import { Component } from "../component/component";
+
+export const ROUTE_COMPONENT_TEMPLATE_NAME = "__owl__-router-component";
+export const ROUTE_COMPONENT_TEMPLATE = `
+
+
+
+
+ `;
+
+export class RouteComponent extends Component {
+ template = ROUTE_COMPONENT_TEMPLATE_NAME;
+ routes: any[] = [];
+ constructor(parent, props) {
+ super(parent, props);
+ const router = this.env.router;
+ for (let name of router.routeIds) {
+ const route = router.routes[name];
+ if (route.component) {
+ this.routes.push({
+ name: route.name,
+ component: "__component__" + route.name
+ });
+ }
+ }
+ }
+}
diff --git a/src/router/Router.ts b/src/router/Router.ts
index 9d45025e..91dd3525 100644
--- a/src/router/Router.ts
+++ b/src/router/Router.ts
@@ -1,6 +1,6 @@
import { Env } from "../component/component";
import { QWeb } from "../qweb/index";
-import { makeDirective } from "./directive";
+import { ROUTE_COMPONENT_TEMPLATE, ROUTE_COMPONENT_TEMPLATE_NAME } from "./RouteComponent";
import { LINK_TEMPLATE, LINK_TEMPLATE_NAME } from "./Link";
import { shallowEqual } from "../utils";
@@ -87,7 +87,7 @@ export class Router {
// setup link and directive
env.qweb.addTemplate(LINK_TEMPLATE_NAME, LINK_TEMPLATE);
- QWeb.addDirective(makeDirective(env));
+ env.qweb.addTemplate(ROUTE_COMPONENT_TEMPLATE_NAME, ROUTE_COMPONENT_TEMPLATE);
}
//--------------------------------------------------------------------------
diff --git a/src/router/directive.ts b/src/router/directive.ts
deleted file mode 100644
index 3ae2ee9c..00000000
--- a/src/router/directive.ts
+++ /dev/null
@@ -1,31 +0,0 @@
-import { RouterEnv } from "./Router";
-
-export function makeDirective(env: RouterEnv) {
- return {
- name: "routecomponent",
- priority: 13,
- atNodeEncounter({ node }): boolean {
- let first = true;
- const router = env.router;
- for (let name of router.routeIds) {
- const route = router.routes[name];
- if (route.component) {
- // make new t t-component element
- const comp = node.ownerDocument.createElement("t");
- comp.setAttribute("t-component", "__component__" + route.name);
- comp.setAttribute(
- first ? "t-if" : "t-elif",
- `env.router.currentRouteName === '${route.name}'`
- );
- first = false;
- for (let param of route.params) {
- comp.setAttribute(param, `env.router.currentParams.${param}`);
- }
- node.appendChild(comp);
- }
- }
- node.removeAttribute("t-routecomponent");
- return false;
- }
- };
-}
diff --git a/tests/router/directive.test.ts b/tests/router/RouteComponent.test.ts
similarity index 86%
rename from tests/router/directive.test.ts
rename to tests/router/RouteComponent.test.ts
index cf9ddbb8..06526a58 100644
--- a/tests/router/directive.test.ts
+++ b/tests/router/RouteComponent.test.ts
@@ -1,9 +1,10 @@
import { Component } from "../../src/component/component";
import { RouterEnv } from "../../src/router/Router";
+import { RouteComponent, ROUTE_COMPONENT_TEMPLATE_NAME } from "../../src/router/RouteComponent";
import { makeTestEnv, makeTestFixture, nextTick } from "../helpers";
import { TestRouter } from "./TestRouter";
-describe("router directive t-routecomponent", () => {
+describe("RouteComponent", () => {
let fixture: HTMLElement;
let env: RouterEnv;
let router: TestRouter | null = null;
@@ -25,7 +26,7 @@ describe("router directive t-routecomponent", () => {
env.qweb.addTemplates(`