处理组件中具有特定功能的请求

时间:2016-07-29 17:51:34

标签: aurelia aurelia-router

我们正在开发一个处理OpenID Connect隐式流的组件。

step 5 of the flow中,"授权服务器将最终用户发送回具有ID令牌的客户端,并且如果请求,则发送访问令牌。"我们希望我们的组件处理该请求,该请求将发送到~/openid-login

我们如何配置Aurelia让它路由到我们组件中的函数?

export class OpenId {

    // how do we route ~/openid-login to this?
    public handleRequest() {

    }

}

注意:Here is the work in progress.

1 个答案:

答案 0 :(得分:2)

在routeConfig中使用navStrategy可以让您在导航到页面之前执行任何操作。见下文:

import { autoinject } from 'aurelia-framework';
import { RouterConfiguration, Router, NavigationInstruction } from 'aurelia-router';

@autoinject
export class App {

    router: Router;

    configureRouter(config: RouterConfiguration, router: Router) {

        let openIdNavStrat = (instruction: NavigationInstruction) => {

            console.log('Do whatever we would like to do.');

            // then redirect to where ever you would like.
            instruction.config.moduleId = 'login';
        }

        config.map([
            { route: ['', 'login'], moduleId: 'login' },
            { route: 'openid-login', navigationStrategy: openIdNavStrat },
        ]);

        this.router = router;
    }
}

此处有关于导航策略的文档:http://aurelia.io/hub.html#/doc/article/aurelia/router/latest/router-configuration/3