When I manually try to open certain page (by typing url in browser) seems like my app can't find what route to use. Page is loading but router-outlet is empty. Also I receive "EmptyError: no elements in sequence". Found that this is some troubles with canActivate method, tried to change Observables to Promise as it says here EmptyError: no elements in sequence but still get error.
My app also have custom base href, defined in index.html
app.routing.ts
const appRoutes: Routes = [
{
path: 'project',
canActivate: [AuthGuard],
canActivateChild: [AuthGuard],
children: [
{
path: 'home',
component: HomeComponent
},
{
path: 'events',
loadChildren: 'app/feature/events/events.module#EventsModule'
},
],
}
];
So when I try to go "localhost/some/base/href/project/home" I get empty page, only app's main menu visible. Also, url became "localhost/some/base/href" Then I can navigate my app by clicking buttons on app's main menu (theirs hyperlinks are 'localhost/some/base/href/project/events/list' for example). This work perfect, routes founded.
Tried to change path in appRoutes to 'some/base/href/project' and now when I go to "localhost/some/base/href/project/home" HomeCompoment is loaded but url became "localhost/some/base/href/some/base/href/project/home" and also buttons on app's main menu stop working.
Of course, I can make redirect
path: '**',
redirectTo: '/project/home',
pathMatch: 'full'
But this will get me only homepage, I want to manually navigate to other components in app.
UPDATE: My authGuard, also tried return Observable and Promise but no effect. isAuthorized() always return true now.
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
let result: boolean = this.authService.isAuthorized();
if (result) {
return true;
}
this.authService.setRedirectUrl(state.url);
return false;
}