File tree Expand file tree Collapse file tree 6 files changed +23
-57
lines changed
__tests__/unit/controllers
get-resources-for-next-location
controllers/resource-store/utils/route-checks Expand file tree Collapse file tree 6 files changed +23
-57
lines changed Original file line number Diff line number Diff line change @@ -69,10 +69,12 @@ describe('getResourcesForNextLocation()', () => {
69
69
describe ( 'when the next route does not match the prev route' , ( ) => {
70
70
it ( 'should request all resources on the next route' , async ( ) => {
71
71
const prevRoute = {
72
+ name : 'prev-route' ,
72
73
path : '/prev-route' ,
73
74
resources : [ mockResource ] ,
74
75
} ;
75
76
const nextRoute = {
77
+ name : 'next-route' ,
76
78
path : '/next-route' ,
77
79
resources : [
78
80
mockResource ,
Original file line number Diff line number Diff line change @@ -3,43 +3,33 @@ import {
3
3
routeHasResources ,
4
4
} from '../../../../../../controllers/resource-store/utils/route-checks' ;
5
5
6
+ const mockRoute = {
7
+ name : 'foo' ,
8
+ path : '/some-path' ,
9
+ component : ( ) => null ,
10
+ } ;
11
+
6
12
describe ( 'routeHasChanged()' , ( ) => {
7
- it ( 'should return true if the route objects do not match' , ( ) => {
13
+ it ( 'should return true if the route name does not match' , ( ) => {
8
14
expect (
9
- routeHasChanged (
10
- // @ts -ignore - not providing all properties on mock
11
- {
12
- path : '/some-path' ,
13
- component : ( ) => null ,
14
- } ,
15
- {
16
- path : '/another-path' ,
17
- component : ( ) => null ,
18
- }
19
- )
15
+ routeHasChanged ( mockRoute , {
16
+ ...mockRoute ,
17
+ name : 'bar' ,
18
+ } )
20
19
) . toBeTruthy ( ) ;
21
20
} ) ;
22
21
23
- it ( 'should return true if the prev route is null ' , ( ) => {
22
+ it ( 'should return true if the route path does not match ' , ( ) => {
24
23
expect (
25
- routeHasChanged (
26
- null ,
27
- // @ts -ignore - not providing all properties on mock
28
- {
29
- path : '/another-path' ,
30
- component : ( ) => null ,
31
- }
32
- )
24
+ routeHasChanged ( mockRoute , {
25
+ ...mockRoute ,
26
+ path : '/bar' ,
27
+ } )
33
28
) . toBeTruthy ( ) ;
34
29
} ) ;
35
30
36
- it ( 'should return false if the routes match' , ( ) => {
37
- const route = {
38
- path : '/some-path' ,
39
- component : ( ) => null ,
40
- } ;
41
- // @ts -ignore - not providing all properties on mock
42
- expect ( routeHasChanged ( route , route ) ) . toBeFalsy ( ) ;
31
+ it ( 'should return false if the route name matches' , ( ) => {
32
+ expect ( routeHasChanged ( mockRoute , { ...mockRoute } ) ) . toBeFalsy ( ) ;
43
33
} ) ;
44
34
} ) ;
45
35
Original file line number Diff line number Diff line change @@ -737,6 +737,7 @@ describe('SPA Router store', () => {
737
737
} ,
738
738
{
739
739
...mockRoute ,
740
+ name : 'bar' ,
740
741
path : '/bar/a' ,
741
742
component : ComponentB ,
742
743
resources : [ resourceA , resourceB ] ,
Original file line number Diff line number Diff line change @@ -175,9 +175,6 @@ export type InvariantRoute = {
175
175
path : string ;
176
176
exact ?: boolean ;
177
177
178
- /** Used to prevent transitions between app groups */
179
- group ?: string ;
180
-
181
178
/** Unique name for the route */
182
179
name : string ;
183
180
@@ -200,26 +197,6 @@ export type Route = InvariantRoute & {
200
197
/** The component to render on match, typed explicitly */
201
198
component : ComponentType < RouteContext > ;
202
199
203
- /**
204
- * Triggered before leaving the route, can trigger full page reload if returns (or resolves) false.
205
- * Defaults to true.
206
- */
207
- canTransitionOut ?: (
208
- currentRouteMatch : MatchedRoute ,
209
- nextRouteMatch : MatchedRoute ,
210
- props : any
211
- ) => boolean | Promise < boolean > ;
212
-
213
- /**
214
- * Triggered before entering the route, can trigger full page reload if returns (or resolves) false.
215
- * Defaults to true.
216
- */
217
- canTransitionIn ?: (
218
- currentRouteMatch : MatchedRoute ,
219
- nextRouteMatch : MatchedRoute ,
220
- props : any
221
- ) => boolean | Promise < boolean > ;
222
-
223
200
/**
224
201
* The resources for the route
225
202
*/
Original file line number Diff line number Diff line change @@ -3,7 +3,5 @@ import { Route } from '../../../../common/types';
3
3
export const routeHasResources = ( route : Route | null ) : boolean =>
4
4
! ! ( route && route . resources && route . resources . length > 0 ) ;
5
5
6
- export const routeHasChanged = (
7
- prev : Route | null ,
8
- next : Route | null
9
- ) : boolean => prev !== next ;
6
+ export const routeHasChanged = ( prev : Route , next : Route ) : boolean =>
7
+ prev . name !== next . name || prev . path !== next . path ;
Original file line number Diff line number Diff line change @@ -109,8 +109,6 @@ export type RouteResourceUpdater<T> = (
109
109
export type InvariantRoute = {
110
110
path: string,
111
111
exact?: boolean,
112
- /** Used to prevent transitions between app groups */
113
- group?: string,
114
112
/** Unique name for the route */
115
113
name: string,
116
114
/**
You can’t perform that action at this time.
0 commit comments