Invalid configuration of route '': redirectTo and canActivate cannot be used together

3.9k Views Asked by At

I want to do laravel angular jwt authentication, so I want to apply guard but it gives me error: Invalid configuration of route '': redirectTo and canActivate cannot be used together. Redirects happen before activation so canActivate will never be executed.

app-routing.module.ts

const routes: Routes = [
  { path:"", redirectTo:"/adress", pathMatch:'full', canActivate:[AuthGuard] },
];
2

There are 2 best solutions below

0
On

RedirectTo and canActivate cannot be used together. Redirects happen before activation so canActivate will never be executed.

In Angular 14, you can no longer use them both in the same configuration. Choose between redirectTo and CanActivate in your inspect/ route configuration, keep the most reliable for your case and you should be good to go.

You can find more details in the following link: https://stackoverflow.com/a/74052870/4983912.

I hope this will help.

1
On

what about using

{
path: '',
pathMatch: 'full',
canActivate:[LoginGuard],
children:[]
},

and have done the redirection process in LoginGuard

but facing device firing up issue at sometime....when opening the app after clearing the data and cache