2

I have 2 differents paths for the same component, and they use resolve data:

//app.routing:
const APP_ROUTES: Routes = [
{
    path: '',
    canActivate: [LoggedInGuard],
    children: [
        {path: '', redirectTo: '/path1', pathMatch: 'full'},
        {path: 'path1', loadChildren: 'app/myModule.module#MyModuleModule'},
        {path: 'path2', loadChildren: 'app/myModule.module#MyModuleModule'}  
    ]
},
{path: '**', redirectTo: ''}
];


export const routing = RouterModule.forRoot(APP_ROUTES);

In myModule.routing:

const MY_MODULE_ROUTES: Routes = [
    {path: '', component: MyModule2Component, resolve: {data: MyModule2Resolver}}
];


export const myModuleRouting = RouterModule.forChild(MY_MODULE_ROUTES);

All this works fine.

Now I would like to control routing from MyModule2Resolver:

@Injectable()
export class  MyModule2Resolver implements Resolve<any[]> {
 constructor(private activatedRoute: ActivatedRoute, private router: Router) {}

 resolve(): Promise<any> {
      //Different action depending on path1 or path2 but
     // I have not this info in activatedRoute or router
 }
}

Is it possible?

1 Answer 1

2

Your activatedRoute contains a property url, which contains information about the url. Use it and write your logic

Sign up to request clarification or add additional context in comments.

1 Comment

activatedRoute is empty in resolver, but I found it, if resolve(data) in data._routerState.url is the value. Thanks

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.