# Routing

## Route Guards

Angular-Token implements the `CanActivate` interface, so it can directly be used as a route guard. If the `signInRedirect` option is set the user will be redirected on a failed (=false) CanActivate using `Router.navigate()`. It currently does not distinguish between user types.

### Example:

```javascript
const routerConfig: Routes = [
  {
    path: '',
    component: PublicComponent
  }, {
    path: 'restricted',
    component: RestrictedComponent,
    canActivate: [AngularTokenService]
  }
];
```

## Redirect original requested URL

If you want to redirect to the protected URL after signing in, you need to set `signInStoredUrlStorageKey` and in your code you can do something like this

### Example:

```javascript
this.tokenService.signIn({
  email:    'example@example.org',
  password: 'secretPassword'
}).subscribe(
  res => {
    // You have to add Router DI in your component
    this.router.navigateByUrl(localStorage.getItem('redirectTo'));
  },
  error =>    console.log(error)
);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://angular-token.gitbook.io/docs/routing.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
