-
Notifications
You must be signed in to change notification settings - Fork 12k
ng build --prod breaks routes created using multiple variables - Error: cannot match any routes #6784
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
Comments
This is essentially the same as #6782. We don't currently support this kind of indirection. |
@kichnan upon discussion in #6782, this one doesn't seem to be related. If http://localhost:4205/ works, but http://localhost/ng-app-sample/ does not and fails with a runtime error about missing routes, then I think the problem you are facing is one of deployment. Make sure to correctly match the |
Thanks @filipesilva . I'm entirely sure it is not a deployment/hosting issue. I have my base-href set properly (without which the app does not work at all). It is definitely a build issue. You can read the "Mention any other details that might be useful." section. The dev-mode bundle file contains the new route variable. The prod bundle file does NOT, at all. Code example:
My original post has the required details without any ambiguity to reproduce the issue. You can try it on a sample app in your local too. Thanks!! |
I'm sorry but I don't follow. The If those aren't the correct repro steps, please clarify. |
I think issue is not about deployment - see screenshot in the topic - app works under that address, just routing does not work. @kichnan means that dynamically created routes (the array dynamically pushed values) does not work when app is built for production with AOT. https://github.com/kichnan/ng-app/blob/master/src/app/app-routes.ts#L30 But works when use statically created routes (plain hardcoded array) https://github.com/kichnan/ng-app/blob/master/src/app/app-routes.ts#L11 Can you confirm? |
@tytskyi thank you! Yes, that is exactly what I meant. @filipesilva I have updated the issue description. Please go through the |
@filipesilva hope you were able to understand/reproduce the issue now. Should this be reopened as a bug then? |
I'm looking at https://github.com/kichnan/ng-app. It doesn't match Looking at them I can tell you this is not supported. Static analysis will never figure out what your This behavior is not a bug then, it is as intended. |
Thanks @filipesilva. Yes, Ok, understood, static analysis will never work on this. So, can you suggest me any alternatives, so that I can add routes like such? I have read about Any help would be great. Thanks. |
It's not really easy to get both AOT and dynamic components AFAIK. I don't have an answer off the top of my head, the better place to ask is Stack Overflow or perhaps the main Angular repo, if a bug is suspected. |
ok great. thank you for your reply. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Bug Report or Feature Request (mark with an
x
)Versions.
@angular/cli: 1.1.1
node: 6.9.4
os: win32 x64
@angular/animations: 4.2.3
@angular/common: 4.2.3
@angular/compiler: 4.2.3
@angular/core: 4.2.3
@angular/forms: 4.2.3
@angular/http: 4.2.3
@angular/platform-browser: 4.2.3
@angular/platform-browser-dynamic: 4.2.3
@angular/router: 4.2.3
@angular/cli: 1.1.1
@angular/compiler-cli: 4.2.3
@angular/language-service: 4.2.3
Repro steps.
Create
app-routing.module.ts
as follows.Run
ng build --prod
.Host application on ANY web server.
RESULT: Route
/foo
does not work - Throws error as mentioned inThe log given by the failure.
section.The log given by the failure.
Error log in web browser dev console when the route is accessed:
Screenshot of error (if required):

Desired functionality.
Route
/foo
should work properly, i.e. should load FooComponent in page.Mention any other details that might be useful.
Alternatively, if you Create
app-routing.module.ts
as follows.(Notice that I am using only one variable now, to set
RouterModule.forRoot()
.)Run
ng build --prod
.Host application on ANY web server.
RESULT: Route
/foo
DOES WORK properly here.Angular app sample repository: https://github.com/kichnan/ng-app
I'm attaching two
main.bundle.js
files.Bundle that works: main.c70bc6dc97933f4525f1.bundle.txt
Bundle that does NOT work: main.d2818fc0b709592f3eeb.bundle.txt
NOTE:
The source file app-routes.ts has TWO variables:
orgRoutes
androutes
. If I use the first-created variable,orgRoutes
, then my application works fine. If I use the second variableroutes
which is created usingorgRoutes
, then the app fails. The bundle does NOT containroutes
variable AT ALL.The text was updated successfully, but these errors were encountered: