@@ -3,32 +3,37 @@ import initRouteStyles from '../utils/init-route-styles';
33// This file is removed from the build in Ember < 3.6
44export function initialize ( appInstance ) {
55 let router = appInstance . lookup ( 'service:router' ) ;
6- router . on ( 'routeDidChange' , function ( transition ) {
7- initRouteStyles ( appInstance , nestedRouteNames ( transition . to ) ) ;
6+ router . on ( 'routeDidChange' , function ( { to } ) {
7+ if ( likeRouteInfo ( to ) ) {
8+ initRouteStyles ( appInstance , nestedRouteNames ( to ) ) ;
9+ }
810 } ) ;
911
10- router . on ( 'routeWillChange' , function ( transition ) {
11- if ( transition . to && / _ l o a d i n g $ / . test ( transition . to . name ) && transition . isActive ) {
12- const routeNames = nestedRouteNames ( transition . to )
13- // loading route names are set with an _loading even though
14- // their path is -loading
15- . map ( name => name . replace ( / _ l o a d i n g $ / , '-loading' ) ) ;
16- initRouteStyles ( appInstance , routeNames ) ;
12+ router . on ( 'routeWillChange' , function ( { to, isActive } ) {
13+ if ( likeRouteInfo ( to ) ) {
14+ if ( / _ l o a d i n g $ / . test ( to . name ) && isActive ) {
15+ const routeNames = nestedRouteNames ( to )
16+ // loading route names are set with an _loading even though
17+ // their path is -loading
18+ . map ( name => name . replace ( / _ l o a d i n g $ / , '-loading' ) ) ;
19+ initRouteStyles ( appInstance , routeNames ) ;
20+ }
1721 }
1822 } ) ;
1923}
2024
21- function nestedRouteNames ( route = { } , routeNames = [ ] ) {
22- if ( route . name ) {
23- routeNames . push ( route . name ) ;
24- }
25-
26- if ( route . parent ) {
27- return nestedRouteNames ( route . parent , routeNames ) ;
25+ function nestedRouteNames ( { name, parent } , routeNames = [ ] ) {
26+ routeNames . push ( name ) ;
27+ if ( parent ) {
28+ return nestedRouteNames ( parent , routeNames ) ;
2829 }
2930 return routeNames ;
3031}
3132
33+ function likeRouteInfo ( info ) {
34+ return info && typeof info === 'object' && info . hasOwnProperty ( 'name' ) ;
35+ }
36+
3237export default {
3338 initialize
3439} ;
0 commit comments