Skip to content

Run multiple resolvers concurrently in router. #14279

@Iverson

Description

@Iverson

I'm submitting a ... (check one with "x")

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior
I set multiple resolvers in my route:

export const routes: Routes = [
  {
    path: '',
    children: appRoutes,
    canActivate: [AuthGuard],
    resolve: {
      capabilities: CapabilitiesResolver,
      userInfo: OrganizationUserResolver,
      organizations: OrganizationResolver
    }
  }
]

each of them implements Resolve interface and return Observable:

@Injectable()
export class CapabilitiesResolver implements Resolve<Endpoint[]> {
  constructor(private capabilitiesService: CapabilitiesService) {}

  resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<Endpoint[]> {
    return this.capabilitiesService.fetch()
  }
}

as result all http requests run sequentially and this is not useful behavior for UX. But if resolvers return Promise instead of Observable:

resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Promise<Endpoint[]> {
    return this.capabilitiesService.fetch().toPromise()
  }

then all requests will be ran concurrently, very implicit behavior...

Expected behavior
No matter what resolve() method return (Observable or Promise) all async operations should be ran concurrently.

What is the motivation / use case for changing the behavior?
For users: Improve UX when router pre-fetch data.
For developers: More explicit router API.

Please tell us about your environment:
@angular/cli: 1.0.0-beta.30
node: 6.2.2
os: darwin x64
@angular/common: 2.4.1
@angular/compiler: 2.4.1
@angular/core: 2.4.1
@angular/forms: 2.4.1
@angular/http: 2.4.1
@angular/platform-browser: 2.4.1
@angular/platform-browser-dynamic: 2.4.1
@angular/router: 3.4.1
@angular/compiler-cli: 2.4.1

  • Angular version: 2.4.1

  • Browser: all

  • Language: TypeScript 2.0.3

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions