Guard throws error attempting to redirect to another pageAngular 2+ wait for method / observable to completeAngular routing canActivate AuthGuard transmit query paramsHow user async guard?Angular 4 routing issue for child routes in nested router-outletAngular routerLink with named outlet (angular 5.0.2)Angular Routing: Instance Creation vs Instance ActivationAngular2 - Routing not working when using router-outlet nameAngular - How to navigate to a named router outlet in a .ts fileAngular - How to navigate to a different component from the same named router outletClarifications on Router with ionic 4
Can I tell a prospective employee that everyone in the team is leaving?
Did people Unsnap to where they were?
Would Jetfuel for a modern jet like an F-16 or a F-35 be producable in the WW2 era?
Are these reasonable traits for someone with autism?
Is it possible to play as a necromancer skeleton?
Where is the logic in castrating fighters?
Make 24 using exactly three 3s
Is the field of q-series 'dead'?
Installed Tankless Water Heater - Internet loss when active
How did these characters "suit up" so quickly?
What is a really good book for complex variables?
Any advice on creating fictional locations in real places when writing historical fiction?
NIntegrate doesn't evaluate
Popcorn is the only acceptable snack to consume while watching a movie
Where's this lookout in Nova Scotia?
Count rotary dial pulses in a phone number (including letters)
Should breaking down something like a door be adjudicated as an attempt to beat its AC and HP, or as an ability check against a set DC?
Could a 19.25mm revolver actually exist?
Should I disclose a colleague's illness (that I should not know) when others badmouth him
Why were helmets and other body armour not commonplace in the 1800s?
How long until a random word with letters "A", "B", "C" ends in the pattern "ABC"?
Grammar Question Regarding "Are the" or "Is the" When Referring to Something that May or May not be Plural
Who will lead the country until there is a new Tory leader?
what kind of chord progession is this?
Guard throws error attempting to redirect to another page
Angular 2+ wait for method / observable to completeAngular routing canActivate AuthGuard transmit query paramsHow user async guard?Angular 4 routing issue for child routes in nested router-outletAngular routerLink with named outlet (angular 5.0.2)Angular Routing: Instance Creation vs Instance ActivationAngular2 - Routing not working when using router-outlet nameAngular - How to navigate to a named router outlet in a .ts fileAngular - How to navigate to a different component from the same named router outletClarifications on Router with ionic 4
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I am trying to have a AuthGuard redirect user to Unauthorized page if they are loggedin.
However it fails every time and i can't figure out why.
Error message:
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'unauthorized'
Error: Cannot match any routes. URL Segment: 'unauthorized'
app.component.html
<router-outlet *ngIf="isAuthenticated()"></router-outlet>
<router-outlet *ngIf="!isAuthenticated()" name="public"></router-outlet>
auth.guard.ts
@Injectable(
providedIn: 'root'
)
export class AuthGuard implements CanActivate
constructor(private router: Router, private authServ: AuthService )
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean
return this.checkUser(route, state);
private checkUser(route: any, state: any): boolean
console.log('AuthorizationGuard is hit');
if(!this.authServ.isAuthorized())
this.router.navigate(['/unauthorized']);
return false;
else
return true;
my app.routing.module routes defined as follows:
path: 'dashboard', component: MainDashboardComponent, canActivate: [AuthGuard] ,
path: 'unauthorized', component: UnauthorizedComponent, outlet: 'public',
path: '', component: HomeComponent, outlet: 'public'
Any advice is appreciated.
I suspect this isssue is tied to named outlet, as when i don't use it, it doesn't appear to occur.
angular
add a comment |
I am trying to have a AuthGuard redirect user to Unauthorized page if they are loggedin.
However it fails every time and i can't figure out why.
Error message:
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'unauthorized'
Error: Cannot match any routes. URL Segment: 'unauthorized'
app.component.html
<router-outlet *ngIf="isAuthenticated()"></router-outlet>
<router-outlet *ngIf="!isAuthenticated()" name="public"></router-outlet>
auth.guard.ts
@Injectable(
providedIn: 'root'
)
export class AuthGuard implements CanActivate
constructor(private router: Router, private authServ: AuthService )
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean
return this.checkUser(route, state);
private checkUser(route: any, state: any): boolean
console.log('AuthorizationGuard is hit');
if(!this.authServ.isAuthorized())
this.router.navigate(['/unauthorized']);
return false;
else
return true;
my app.routing.module routes defined as follows:
path: 'dashboard', component: MainDashboardComponent, canActivate: [AuthGuard] ,
path: 'unauthorized', component: UnauthorizedComponent, outlet: 'public',
path: '', component: HomeComponent, outlet: 'public'
Any advice is appreciated.
I suspect this isssue is tied to named outlet, as when i don't use it, it doesn't appear to occur.
angular
add a comment |
I am trying to have a AuthGuard redirect user to Unauthorized page if they are loggedin.
However it fails every time and i can't figure out why.
Error message:
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'unauthorized'
Error: Cannot match any routes. URL Segment: 'unauthorized'
app.component.html
<router-outlet *ngIf="isAuthenticated()"></router-outlet>
<router-outlet *ngIf="!isAuthenticated()" name="public"></router-outlet>
auth.guard.ts
@Injectable(
providedIn: 'root'
)
export class AuthGuard implements CanActivate
constructor(private router: Router, private authServ: AuthService )
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean
return this.checkUser(route, state);
private checkUser(route: any, state: any): boolean
console.log('AuthorizationGuard is hit');
if(!this.authServ.isAuthorized())
this.router.navigate(['/unauthorized']);
return false;
else
return true;
my app.routing.module routes defined as follows:
path: 'dashboard', component: MainDashboardComponent, canActivate: [AuthGuard] ,
path: 'unauthorized', component: UnauthorizedComponent, outlet: 'public',
path: '', component: HomeComponent, outlet: 'public'
Any advice is appreciated.
I suspect this isssue is tied to named outlet, as when i don't use it, it doesn't appear to occur.
angular
I am trying to have a AuthGuard redirect user to Unauthorized page if they are loggedin.
However it fails every time and i can't figure out why.
Error message:
ERROR Error: Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'unauthorized'
Error: Cannot match any routes. URL Segment: 'unauthorized'
app.component.html
<router-outlet *ngIf="isAuthenticated()"></router-outlet>
<router-outlet *ngIf="!isAuthenticated()" name="public"></router-outlet>
auth.guard.ts
@Injectable(
providedIn: 'root'
)
export class AuthGuard implements CanActivate
constructor(private router: Router, private authServ: AuthService )
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean
return this.checkUser(route, state);
private checkUser(route: any, state: any): boolean
console.log('AuthorizationGuard is hit');
if(!this.authServ.isAuthorized())
this.router.navigate(['/unauthorized']);
return false;
else
return true;
my app.routing.module routes defined as follows:
path: 'dashboard', component: MainDashboardComponent, canActivate: [AuthGuard] ,
path: 'unauthorized', component: UnauthorizedComponent, outlet: 'public',
path: '', component: HomeComponent, outlet: 'public'
Any advice is appreciated.
I suspect this isssue is tied to named outlet, as when i don't use it, it doesn't appear to occur.
angular
angular
asked Mar 24 at 4:08
AeseirAeseir
3,91342768
3,91342768
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
The syntax for secondary outlet is different you need to define object is the frst parameter to link parameter of the array
Try this
private checkUser(route: any, state: any): boolean {
console.log('AuthorizationGuard is hit');
if(!this.authServ.isAuthorized())
this.router.navigate([outlets:public:['unauthorized']]);
return false;
else
return true;
add a comment |
You added the unauthorized path for outlet public so it is happening.
You can remove the outlet option from the app.routing.module.ts
path: 'unauthorized', component: UnauthorizedComponent, outlet: 'public',
TO:
path: 'unauthorized', component: UnauthorizedComponent ,
And html
<router-outlet *ngIf="isAuthenticated()"></router-outlet>
<router-outlet *ngIf="!isAuthenticated()" name="public"></router-outlet>
To
<router-outlet></router-outlet>
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320645%2fguard-throws-error-attempting-to-redirect-to-another-page%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The syntax for secondary outlet is different you need to define object is the frst parameter to link parameter of the array
Try this
private checkUser(route: any, state: any): boolean {
console.log('AuthorizationGuard is hit');
if(!this.authServ.isAuthorized())
this.router.navigate([outlets:public:['unauthorized']]);
return false;
else
return true;
add a comment |
The syntax for secondary outlet is different you need to define object is the frst parameter to link parameter of the array
Try this
private checkUser(route: any, state: any): boolean {
console.log('AuthorizationGuard is hit');
if(!this.authServ.isAuthorized())
this.router.navigate([outlets:public:['unauthorized']]);
return false;
else
return true;
add a comment |
The syntax for secondary outlet is different you need to define object is the frst parameter to link parameter of the array
Try this
private checkUser(route: any, state: any): boolean {
console.log('AuthorizationGuard is hit');
if(!this.authServ.isAuthorized())
this.router.navigate([outlets:public:['unauthorized']]);
return false;
else
return true;
The syntax for secondary outlet is different you need to define object is the frst parameter to link parameter of the array
Try this
private checkUser(route: any, state: any): boolean {
console.log('AuthorizationGuard is hit');
if(!this.authServ.isAuthorized())
this.router.navigate([outlets:public:['unauthorized']]);
return false;
else
return true;
answered Mar 24 at 4:22
ChellappanChellappan
6,1942521
6,1942521
add a comment |
add a comment |
You added the unauthorized path for outlet public so it is happening.
You can remove the outlet option from the app.routing.module.ts
path: 'unauthorized', component: UnauthorizedComponent, outlet: 'public',
TO:
path: 'unauthorized', component: UnauthorizedComponent ,
And html
<router-outlet *ngIf="isAuthenticated()"></router-outlet>
<router-outlet *ngIf="!isAuthenticated()" name="public"></router-outlet>
To
<router-outlet></router-outlet>
add a comment |
You added the unauthorized path for outlet public so it is happening.
You can remove the outlet option from the app.routing.module.ts
path: 'unauthorized', component: UnauthorizedComponent, outlet: 'public',
TO:
path: 'unauthorized', component: UnauthorizedComponent ,
And html
<router-outlet *ngIf="isAuthenticated()"></router-outlet>
<router-outlet *ngIf="!isAuthenticated()" name="public"></router-outlet>
To
<router-outlet></router-outlet>
add a comment |
You added the unauthorized path for outlet public so it is happening.
You can remove the outlet option from the app.routing.module.ts
path: 'unauthorized', component: UnauthorizedComponent, outlet: 'public',
TO:
path: 'unauthorized', component: UnauthorizedComponent ,
And html
<router-outlet *ngIf="isAuthenticated()"></router-outlet>
<router-outlet *ngIf="!isAuthenticated()" name="public"></router-outlet>
To
<router-outlet></router-outlet>
You added the unauthorized path for outlet public so it is happening.
You can remove the outlet option from the app.routing.module.ts
path: 'unauthorized', component: UnauthorizedComponent, outlet: 'public',
TO:
path: 'unauthorized', component: UnauthorizedComponent ,
And html
<router-outlet *ngIf="isAuthenticated()"></router-outlet>
<router-outlet *ngIf="!isAuthenticated()" name="public"></router-outlet>
To
<router-outlet></router-outlet>
answered Mar 24 at 4:15
Omkar YadavOmkar Yadav
310412
310412
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55320645%2fguard-throws-error-attempting-to-redirect-to-another-page%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown