@@ -5,6 +5,7 @@ import ngRedux from 'ng-redux';
55import { combineReducers } from 'redux' ;
66import thunk from 'redux-thunk' ;
77import createLogger from 'redux-logger' ;
8+ import { default as DevTools , runDevTools } from './devTools' ;
89
910import ngReduxRouter from '../src' ;
1011
@@ -81,6 +82,7 @@ export default angular
8182 <h2>Child View 1</h2>
8283 <button ng-click="stateGo('app.child2')">stateGo View 2</button>
8384 <button ng-click="stateTransitionTo('app.child2')">stateTransitionTo View 2</button>
85+ <button ng-click="stateTransitionTo('app.child3', {id: '4'})">stateTransitionTo View 3, ID: 4</button>
8486 </div>
8587 `
8688 }
@@ -122,6 +124,7 @@ export default angular
122124 template : `
123125 <div class="child-view">
124126 <h2>Child View 3</h2>
127+ <h3>ID: {{router.currentParams.id}}</h3>
125128 <button ng-click="stateGo('app.child3', {id: '1'})">$state.go View 3, ID: 1</button>
126129 <button ng-click="stateGo('app.child3', {id: '2'})">$state.go View 3, ID: 2</button>
127130 <button ng-click="stateGo('app.child3', {id: '3'})">$state.go View 3, ID: 3</button>
@@ -155,27 +158,28 @@ export default angular
155158 router
156159 } ) ;
157160
158- $ngReduxProvider . createStoreWith ( reducers , [ 'ngUiRouterMiddleware' , logger , thunk ] ) ;
161+ const middlewares = [ 'ngUiRouterMiddleware' , thunk , logger ] ;
162+ const enhancers = [ DevTools . instrument ( ) ] ;
163+
164+ $ngReduxProvider . createStoreWith ( reducers , middlewares , enhancers ) ;
159165 } )
160- . run ( ( $rootScope , $state , $ngRedux , $urlRouter ) => {
166+ . run ( runDevTools )
167+ . run ( ( $transitions , $state , $ngRedux ) => {
161168
162169 // If save something to the store, dispatch will force state change update
163170 console . log ( 'will do dispatch' ) ;
164171 $ngRedux . dispatch ( { type : 'SOME_ACTION' } ) ;
165172 console . log ( 'did dispatch' ) ;
166173
167- $rootScope . $on ( '$stateChangeStart' , function ( evt , to , params ) {
168- if ( to . prohibited ) {
169- evt . preventDefault ( ) ;
174+ let matchCriteria = { to : ( state ) => state . prohibited } ;
175+
176+ $transitions . onBefore ( matchCriteria , ( $transition$ ) => {
177+ if ( $transition$ . to ( ) . prohibited ) {
170178 console . log ( 'prohibited state change cancelled' ) ;
171- $state . go ( 'app' ) ;
179+ return $state . target ( 'app' , { location : 'replace' } ) ;
172180 }
173181 } ) ;
174182
175- console . log ( '$stateChangeStart callback is ready' ) ;
176- console . log ( 'enable $urlRouter listening' ) ;
177-
178- $urlRouter . sync ( ) ;
179- $urlRouter . listen ( ) ;
183+ console . log ( '$transitions.onBefore callback is ready' ) ;
180184 } )
181185 . name ;
0 commit comments