1

I am working on an angular app which I recently converted into angular 5 from angular 4.2( although I am not using any feature of angular 5 yet).

I need to execute an resolver on a particular route on demand ( from the code when a certain condition met). for example

if ( a === b) {
     //execute resolver
  }

I am not sure, what is the right way of doing that as resolver is a class just like any other typescript class.

2
  • So I'm assuming you need a condition when you first go to the route, or is it after you have arrived at the route? Commented Apr 10, 2018 at 19:51
  • I need a condition when I go first to the route. your assumption is right. Commented Apr 10, 2018 at 20:07

2 Answers 2

1

I'll give it a shot. Just a generalization since you haven't posted any actual code. I used a simple ternary to get a task done earlier this year

app.module.ts provider excerpt of Resolver

  {
        provide: 'conditionResolver', useValue: (route: ActivatedRouteSnapshot, state: RouterStateSnapshot) => {
            //Something like this
            window.open((route.data as any).otherUrl);
        }
    }

app.router.ts route excerpt of Implementation

    path: 'SomeComponentURL', component: SomeComponent, resolve: {
        url: 'conditionResolver'
    },
    data: {
        condition: (someCondition != '#/SomeComponent')
            ? 'doSomething()' : orDoSomethingElse()
    }
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. I actually end-up doing by updating my route config and putting an condition in the resolver resolve method itself. +1 for another approach.
1

I actually end-up doing by updating my route config and putting an condition in the resolver's resolve method itself.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.