question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItΒ collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Routing: canActivate is not created in --prod when using concat

See original GitHub issue

🐞 bug report

Description

When using array_of_guards.concat(guard) as canActivate parameter in a route and building app with --prod the resulting script doesn’t have canActivate variable defined. When using […array_of_guards, guard] it works fine. The issue doesn’t show when not in --prod meaning that a dev environment works fine.

πŸ”¬ Minimal Reproduction

https://github.com/mlechnioppg/guards-bug

Clone repo then run: ng build --prod Use http-server to run, eg: http-server dist/guards Click links while watching console and see that guards don’t fire when clicking one link. When testing using ng serve all logs show properly when clicked.

🌍 Your Environment

Angular Version:



Angular CLI: 7.3.6
Node: 8.12.0
OS: win32 x64
Angular: 7.2.9
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.12.4
@angular-devkit/build-angular     0.12.4
@angular-devkit/build-optimizer   0.12.4
@angular-devkit/build-webpack     0.12.4
@angular-devkit/core              7.2.4
@angular-devkit/schematics        7.3.6
@angular/cli                      7.3.6
@ngtools/webpack                  7.2.4
@schematics/angular               7.3.6
@schematics/update                0.13.6
rxjs                              6.3.3
typescript                        3.2.4
webpack                           4.28.4

Anything else relevant?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Stanteqcommented, Mar 21, 2019

I have the same issue when I want to attach the guard for all routes

const routes: Routes = [{
    path: "",
    loadChildren: "./home/home.module#HomeModule",
    data: { }
  },  {
    path: "test",
    loadChildren: "./test/test.module#TestModule",
    data: { }
  }]

 routes.forEach((route: Route) => {
   route.canActivate = [GuardService];
 });

0reactions
angular-automatic-lock-bot[bot]commented, Aug 8, 2020

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple canActivate guards all run when first fails
The problem is that when I access the route and I am not logged in I hit the AuthGuard , which fails and...
Read more >
CanActivate - Angular
Interface that a class can implement to be a guard deciding if a route can be activated. If all guards return true ,...
Read more >
Implementing Route Protection in Angular using CanActivate
This article will go through route protection in Angular and a step-by-step guide on implementing it using the CanActivate interface.
Read more >
Angular 14 Functional Router Guards: What They Are & How ...
If for example is not authenticated we should restrict access to that ... CanLoad: While we can use CanActivate to prevent an unauthorizedΒ ......
Read more >
Angular 6 Tutorial 17: Routing Protection (Login App Part 3)
This tutorial shows you how to protect routes using guards in angular and implement them in a simple login application.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found