site
site

Reputation: 247

router outside canActivate: [AuthGuard] doesn't work

I have a problem with my routing.

I tried to used this code:

const routes: Routes = [
  {
    path: 'home', component: HomeComponent, canActivate: [AuthGuard], children: [
      { path: 'events', component: EventsComponent },
      { path: 'package', component: PackageComponent },
      { path: 'settings', component: SettingsComponent }
    ]
  },
  { path: 'login', component: LoginComponent },
  { path: '**', redirectTo: 'home' },
  { path: "register", component: RegisterComponent },
  { path: "usersforgetpassword", component: ResetPassComponent }
];

enter image description here

Doesn't work navigate, forgot password (ResetPassComponent) and new account(RegisterComponent ).

Html code:

<StackLayout>
        <Label [nsRouterLink]="['/usersforgetpassword']" class="text-center footnote">
            <FormattedString>
                <Span text="Forgot password?  "></Span>
            </FormattedString>
        </Label>
    </StackLayout>
    <StackLayout>
        <Label [nsRouterLink]="['/register']" class="text-center footnote">
            <FormattedString>
                <Span text="New Account "></Span>
            </FormattedString>
        </Label>
    </StackLayout>

Please, can you ask me, what is the problem in my router? I can't understand.

Thnx

Upvotes: 1

Views: 485

Answers (2)

Akshay Rana
Akshay Rana

Reputation: 1485

Wildcard route should always be in the end, otherwise routes below that won't work as it matches all possible strings.

Refer : https://angular.io/guide/router#configuration

Upvotes: 0

eduPeeth
eduPeeth

Reputation: 1868

Please place these

{ path: "register", component: RegisterComponent },
  { path: "usersforgetpassword", component: ResetPassComponent }

Before

 { path: '**', redirectTo: 'home' } 

Upvotes: 1

Related Questions