From 23792c92acd52bd11d9469f3bb1f214399b8d7ab Mon Sep 17 00:00:00 2001 From: Ostap Chervak Date: Wed, 3 Jan 2018 17:29:06 +0200 Subject: [PATCH] fix(router): Incorrect values passed to route context --- examples/simple-ts/pages/root.page.tsx | 14 ++++++++++++-- examples/simple-ts/store/index.ts | 1 + src/poa.tsx | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/examples/simple-ts/pages/root.page.tsx b/examples/simple-ts/pages/root.page.tsx index d2a7499..4760036 100644 --- a/examples/simple-ts/pages/root.page.tsx +++ b/examples/simple-ts/pages/root.page.tsx @@ -1,7 +1,7 @@ import * as React from 'react'; -import { Link, Translator, Component, observable, i18n } from '../../../src/poa'; +import { Link, Translator, Component, observable, i18n, Route } from '../../../src/poa'; -import { Store, Actions } from '../store'; +import { Store, Actions, RouterHookOpts } from '../store'; @Component({ namespaces: ['common', 'pages'] }) export class RootPage extends React.Component { @@ -11,6 +11,16 @@ export class RootPage extends React.Component { @observable localState = { newHello: '' }; + static canActivate(route: Route) { + const { store }: RouterHookOpts = route.context; + + if (!store.helloText) { + return false; + } + + return true; + } + render() { return ( diff --git a/examples/simple-ts/store/index.ts b/examples/simple-ts/store/index.ts index 70eae4d..2df9499 100644 --- a/examples/simple-ts/store/index.ts +++ b/examples/simple-ts/store/index.ts @@ -6,3 +6,4 @@ export type Actions = typeof actions; export type MutationOpts = { store: Store }; export type SideEffectOpts = { store: Store; actions: Actions }; +export type RouterHookOpts = { store: Store; actions: Actions }; diff --git a/src/poa.tsx b/src/poa.tsx index eb0b8e5..bbfd094 100644 --- a/src/poa.tsx +++ b/src/poa.tsx @@ -39,8 +39,6 @@ export async function boot(config: PoaBootConfig) { await reactDomPromisify(, config.react.htmlNode); } - const { router } = await bootRouter(config); - await bootstrapLocalization(config.i18n || {}); if (config.state) { @@ -51,6 +49,8 @@ export async function boot(config: PoaBootConfig) { await bootstrapState({}, [], config.env); } + const { router } = await bootRouter(config); + await reactDomPromisify( ,