Shaun Luttin
Shaun Luttin

Reputation: 141512

Handle a request with a specific function in a component

We are developing a component that handles OpenID Connect's implicit flow.

In step 5 of the flow, the "Authorization Server sends the End-User back to the Client with an ID Token and, if requested, an Access Token." We would like our component to handle that request, which will be to ~/openid-login.

How do we configure Aurelia to have it route to a function in our component?

export class OpenId {

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

    }

}

Note: Here is the work in progress.

Upvotes: 0

Views: 58

Answers (1)

Jeremy Gonzalez
Jeremy Gonzalez

Reputation: 232

Using a navStrategy within your routeConfig will allow you to do what ever you like before navigating to a page. See below:

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;
    }
}

There is documentation on Navigation Strategies here: http://aurelia.io/hub.html#/doc/article/aurelia/router/latest/router-configuration/3

Upvotes: 2

Related Questions