Skip to content

Router Guards not listed in router.config #16630

Closed

Description

@Karasuni

I'm submitting a ... (check one with "x")

[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

Current behavior

The Angular.io guide on routing suggests logging @angular/router's router.config to see the configuration of your router tree. In the example provided you see

  {
    "path": "admin",
    "loadChildren": "app/admin/admin.module#AdminModule",
    "canLoad": [
      null
    ]
  },

Even though a guard is registered the canLoad parameter is null, implying the service is not resolved and registered for callback.

Expected behavior

  {
    "path": "admin",
    "loadChildren": "app/admin/admin.module#AdminModule",
    "canLoad": [
      "AuthGuard"
    ]
  },

Minimal reproduction of the problem with instructions
Open the official example app and look at the console log.

What is the motivation / use case for changing the behavior?
Incorrect / confusing logging complicates development.

Please tell us about your environment: Angular.io

  • Angular version: 4.1.1

Activity

  1. jasonaden commented on Dec 12, 2017

    @jasonaden
    Contributor

    The AuthGuard should be an injectable symbol, not a string. That should fix this issue.

  2. Karasuni commented on Dec 13, 2017

    @Karasuni
    Author

    @jasonaden Are you saying there is a fix for this issue? I've loaded up the official example and still see "canLoad": [ null ] even though there is an AuthGuard set.

  3. gkalpak commented on Dec 13, 2017

    @gkalpak
    Member

    This is a docs issue, not a router issue. The logged null value is a result of how JSON.stringify() stringifies functions inside an array. In order to avoid confusion, one could use a custom replacer in JSON.stringify() that uses the function's name instead:

    -console.log('Routes: ', JSON.stringify(router.config, undefined, 2));
    +const replacer = (key, value) => (typeof value === 'function') ? value.name : value;
    +console.log('Routes: ', JSON.stringify(router.config, replacer, 2));

    This should be changed in (probably with a explanatory comment):

    constructor(router: Router) {
    console.log('Routes: ', JSON.stringify(router.config, undefined, 2));
    }

  4. kapunahelewong commented on Feb 23, 2018

    @kapunahelewong
    Contributor

    @jenniferfell This issue needs an update in the example as well as the doc.

  5. added this to the needsTriage milestone on Feb 28, 2018
  6. modified the milestones: needsTriage, Backlog on Apr 25, 2018
  7. jenniferfell commented on Apr 25, 2018

    @jenniferfell
    Contributor

    It looks like this has been resolved. The example now looks like the "expected behavior" above, only without the AuthGuard being a string:

    path: 'admin',
    loadChildren: 'app/admin/admin.module#AdminModule',
    canLoad: [AuthGuard]

    @brandonroberts @gkalpak @jasonaden What do you think? Can we close this as resolved? Thanks!

  8. brandonroberts commented on Apr 25, 2018

    @brandonroberts
    Contributor

    I'm still seeing the same behavior being logged to the console in the stackblitz example

  9. brandonroberts commented on Oct 8, 2018

    @brandonroberts
    Contributor

    Fixed via #20023

  10. angular-automatic-lock-bot commented on Sep 14, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  11. locked and limited conversation to collaborators on Sep 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions