Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ngrx/router-store throws error with navigation in canLoad method #213

Closed
michaelsaprykin opened this issue Jul 29, 2017 · 0 comments
Closed

Comments

@michaelsaprykin
Copy link

michaelsaprykin commented Jul 29, 2017

I'm submitting a...


[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report  
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request

What is the current behavior?

When trying to make navigation by pasting the URL in the browser (not by any angular routing methods) canLoad function, ngrx/router-store throws an error:

TypeError: null is not an object (evaluating 'this.storeState['routerReducer'].state.url') navigateIfNeeded

Here is the repo to reproduce the issue: https:/MikeSaprykin/ngrx-router-store-canLoad-bug ---> start the app, and navigate in browser by pasting localhost:4200/dashboard in the search bar.

Expected behavior:

All good, lazy-loading route not loaded, redirected to an appropriate route

Minimal reproduction of the problem with instructions:

Here are some files to reproduce:

app.routing.ts

export const APP_ROUTES: Routes = [
  {
    path: '',
    redirectTo: 'login',
    pathMatch: 'full',
  },
  {
    path: 'login',
    loadChildren: './pages/login/login.module#LoginModule',
    canActivate: [
      LoginGuard
    ]
  },
  {
    path: 'dashboard',
    loadChildren: './pages/dashboard/dashboard.module#DashboardModule',
    canLoad: [
      DashboardGuard
    ]
  }
];

DashboardGuard file:

@Injectable()
export class DashboardGuard implements CanLoad {

  constructor(public router: Router) {}

  canLoad(route): Observable<boolean> | Promise<boolean> | boolean {
    this.router.navigate(['/login']);
    return false;
  }
}

Version of affected browser(s),operating system(s), npm, node and ngrx:

angular/cli: 1.2.4
npm: 5.3.0
node: 8.0.0
os: darwin x64

ngrx/effects: ^4.0.1,
ngrx/router-store": ^4.0.0,
ngrx/store: ^4.0.0,
ngrx/store-devtools: ^4.0.0,

Other information:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants