angular
angular copied to clipboard
Angular router strange route matching behavior
Consider the following 2 routes and components:
/heroes:
import 'package:angular/angular.dart';
@Component(
selector: 'heroes-listing',
template: 'Heroes listing...',
)
class HeroesListingComponent implements OnInit {
@override
void ngOnInit() {
print('Heroes listing init');
}
}
/heroes/:id:
import 'package:angular/angular.dart';
@Component(
selector: 'hero-detail',
template: 'Hero detail...',
)
class HeroDetailComponent implements OnInit {
@override
void ngOnInit() {
print('Hero detail init');
}
}
When you access /heroes everything is as expected and prints "Heroes listing init".
When you access the sub route /heroes/1 it renders the HeroDetailComponent but prints both "Heroes listing init" and "Hero detail init".
What is also more strange is that trying to access an invalid route such as /heroessomething will also call the HeroesComponent init, but will not render it.
Is this a bug with the path matching or is intended behavior (probably router_impl.dart#L228)?
I'm using AngularDart 6.0.0-alpha+1 and AngularRouter 2.0.0-alpha+24