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;








0















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.










share|improve this question




























    0















    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.










    share|improve this question
























      0












      0








      0








      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.










      share|improve this question














      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 24 at 4:08









      AeseirAeseir

      3,91342768




      3,91342768






















          2 Answers
          2






          active

          oldest

          votes


















          1














          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;






          share|improve this answer






























            0














            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>





            share|improve this answer























              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
              );



              );













              draft saved

              draft discarded


















              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









              1














              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;






              share|improve this answer



























                1














                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;






                share|improve this answer

























                  1












                  1








                  1







                  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;






                  share|improve this answer













                  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;







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 24 at 4:22









                  ChellappanChellappan

                  6,1942521




                  6,1942521























                      0














                      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>





                      share|improve this answer



























                        0














                        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>





                        share|improve this answer

























                          0












                          0








                          0







                          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>





                          share|improve this answer













                          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>






                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Mar 24 at 4:15









                          Omkar YadavOmkar Yadav

                          310412




                          310412



























                              draft saved

                              draft discarded
















































                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

                              Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

                              Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript