angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

V1.7.0 Nested routing not working

Open kanji-keraliya opened this issue 8 years ago • 41 comments

I updated latest @angular/[email protected] and now nested routing not work.I created two routing file like app-routing.module.ts and report-route.module.ts.

report-route.module.ts used in app-routing.module.ts.after updating to latest Angular CLI not working. and its working in V1.6.8

Error is Uncaught (in promise) TypeError: undefined is not a function

kanji-keraliya avatar Feb 16 '18 12:02 kanji-keraliya

Had this same issue. I fixed it by making a few changes to my Routes file. Original:

import { RouterModule } from '@angular/router';

const appRoutes= [
{ path: '**', redirectedTo: '', component: HomeComponent }
]

export const AppRouter = RouterModule.forRoot(appRoutes);

Updated:

import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';

const appRoutes: Routes = [
{ path: '**', redirectTo: '', component: HomeComponent }
]

@NgModule({
	imports: [
		RouterModule.forRoot(
			appRoutes,
			{ enableTracing: false } // <-- debugging purposes only
		)
	],
	exports: [
		RouterModule
	]
})
export class AppRouter {}

salvdev avatar Apr 13 '18 17:04 salvdev

Same issue here with CLI 1.7.2. As it has been mentioned in #9775 compiling with --aot seems to fix the problem which is acceptable workaround in my case until its fixed. Really would like to avoid downgrading :wink:

TobiasBreuer avatar Apr 16 '18 13:04 TobiasBreuer

I upgraded to 1.7.4, and that version is working. I also used --aot, same as Tobias.

dewwwald avatar Apr 19 '18 14:04 dewwwald

Upgrading to 1.7.4 worked for me; we're also using --aot.

ghostlandr avatar Apr 27 '18 17:04 ghostlandr

Downgrading to 1.6.8 worked for me as well!

ashitosh31 avatar May 03 '18 05:05 ashitosh31

1.7.4 also works with the --aot flag but not without.

CDuPlooy avatar May 05 '18 09:05 CDuPlooy

I experience the same error with @angular/cli: 6.0.0 dev build succeeds but there is runtime error Uncaught (in promise): TypeError: undefined is not a function.

AOT works

fixed: see this comment module import order matters!

GeorgeKnap avatar May 05 '18 10:05 GeorgeKnap

Same here, work with AOT

fuchien avatar May 14 '18 01:05 fuchien

Had the same issue. Fixed it by removing my lazy loaded modules from AppModule since they are, you know, lazy loaded 😄 This comment along with the one GeorgeKnap linked to helped me fix this.

bluecaret avatar May 22 '18 15:05 bluecaret

I have same issue. My lazy loaded modules are under app/ but ng build --watch does not work I get same error. If I do ng build --prod then everything works fine but it makes development hard. I am on cli version 6.0.8.

Anyone know how to fix?

GuerrillaCoder avatar Jun 26 '18 13:06 GuerrillaCoder

@GuerrillaCoder The workaround with AOT explained above works for everyone. Did you try it ?

martin-g avatar Jun 26 '18 13:06 martin-g

Ahh sorry I missed it, yes that works.

GuerrillaCoder avatar Jun 26 '18 13:06 GuerrillaCoder

Same issue here with angular/cli: 1.7.3, work with aot

kufre-okon avatar Jul 03 '18 17:07 kufre-okon

@bluecaret thank you. why the error just only warning that I import lazy module at app.module.ts is wrong?

hiepxanh avatar Aug 15 '18 17:08 hiepxanh

I'm still getting that same error sadly, did try with ng serve --aot as well. I've messed around with it so many time that I'm losing hope - most solid error is that it can't reach my child routes (although occasionally it will give me the undefined error instead).

Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'parent/child'
Error: Cannot match any routes. URL Segment: 'parent/child'

I'm clicking on a link to my child route while operating from the parent route when the error is thrown. I'm on Angular 5.2 and CLI 1.7.4 - did try downgrading to 1.6.8 but met with same results.

k80oshea avatar Aug 27 '18 21:08 k80oshea

uninstall global and local cli, and reinstall and check that they are identical, check package-lock.json, check that you have the good typescript version. I had a problem a while back and resolve it like this.

ghost avatar Aug 27 '18 21:08 ghost

I would recommended to go for a specific version of cli with other third party plugins which supports same version, for me 1.6.8 worked perfectly.

On Tue, 28 Aug 2018, 2:59 am k80oshea, [email protected] wrote:

I'm still getting that same error sadly, did try with ng serve --aot as well. I've messed around with it so many time that I'm losing hope - most solid error is that it can't reach my child routes (although occasionally it will give me the undefined error instead).

Uncaught (in promise): Error: Cannot match any routes. URL Segment: 'parent/child' Error: Cannot match any routes. URL Segment: 'parent/child'

I'm clicking on a link to my child route while operating from the parent route when the error is thrown. I'm on Angular 5.2 and CLI 1.7.4 - did try downgrading to 1.6.8 but met with same results.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/9651#issuecomment-416374956, or mute the thread https://github.com/notifications/unsubscribe-auth/ATvlkgB7xdtcWHnbENy6GQ7ozaRjG_Bvks5uVGSngaJpZM4SIQJT .

ashitosh31 avatar Aug 28 '18 12:08 ashitosh31

@jfborie @ashitosh31 thanks - it didn't seem to work right off the bat, but I think it helped after I restructured some more after following this example from the angular docs for my routing

k80oshea avatar Aug 28 '18 14:08 k80oshea

For anyone else with quite old angular code (eg. v2 or 3 or 4) it is possible that you might be importing global services that you have written in your app.component.ts (in the providers array) as this was an old-style way you could import them. So if you have a providers array in your app.component.ts then delete it and the import statements and instead place them in app.module.ts.

This fixed this exact error for me.

rmcsharry avatar Sep 02 '18 23:09 rmcsharry

Closing as CLI 1.x is no longer actively maintained. Please update to the latest support version (currently 6.2.4). If the observed problems still exist after updating, please open an new issue detailing the version and environment information. Thank you.

clydin avatar Oct 01 '18 19:10 clydin