When accessing /my/route/8000
, everything functions as expected.
However, attempting to access /my/route
without any route parameters results in an error:
An error occurred: 'null' was provided instead of a stream. Ensure you provide an Observable, Promise, Array, or Iterable.
ngOnInit() {
// the observable method
this.route.paramMap
.switchMap((params: ParamMap) => {
this.number = params.get('number');
return params.get('number');
})
.subscribe((number) => { return; });
}
Defined Routes
export const routes: Routes = [{
path : 'my',
children: [{
path : '',
pathMatch : 'full',
redirectTo: 'route'
}, {
path : 'route',
component: SubscriberRegisterComponent,
}, {
path : 'route/:number', // captures route parameters
component: SubscriberRegisterComponent,
}]
}];
Why am I unable to access my route directly without providing route parameters?
By temporarily commenting out the observable method and using the no-observable method
, the route can be accessed with empty parameters
this.number = this.route.snapshot.paramMap.get('number ');