Skip to content

Commit f6e06ad

Browse files
fix(history): pushing/replacing a route sometimes resulted in a back/next action (#56)
Previously, actions dispatched by the user to push/replace the route were intercepted and turned into back/next actions if they matched the next or previous entry in the history stack. This meant that it was not possible to push/replace the next/previous route in the history stack. This change removes that behaviour, so that the direction of dispatched actions are preserved. BREAKING CHANGE: dispatching a route that matches the previous/next route in the history stack is no longer reinterpreted as a back/next action BREAKING CHANGE: history functions `set`/`setParams`/`setState`/`setQuery`/`setHash`/`setBasename` no longer accept a function as an argument BREAKING CHANGE: history functions `set`/`setParams`/`setState`/`setQuery` no longer merge their arguments with the existing params/state/query BREAKING CHANGE: history functions `back`/`next`/`jump` no longer accept a state argument Fixes #48
1 parent 0daa0b4 commit f6e06ad

23 files changed

Lines changed: 2512 additions & 6871 deletions

File tree

packages/integration-tests/__helpers__/createTest.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,12 @@ const createSnipes = (testName, routesMap, initialPath, opts, callback) => {
194194
return res
195195
},
196196
snapPop: async (direction, prefix = '') => {
197-
const res = await pop(direction)
197+
let res
198+
if (typeof direction === 'string') {
199+
res = await pop(direction)
200+
} else {
201+
res = await direction.call(history)
202+
}
198203

199204
if (opts.snipesOnly) return res
200205

packages/integration-tests/__tests__/integration/__snapshots__/createAction.js.snap

Lines changed: 40 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ Object {
194194
"hash": "",
195195
"location": Object {
196196
"blocked": null,
197-
"direction": "backward",
197+
"direction": "forward",
198198
"entries": Array [
199199
Object {
200200
"basename": "",
@@ -226,13 +226,28 @@ Object {
226226
"state": Object {},
227227
"type": "SECOND",
228228
},
229+
Object {
230+
"basename": "",
231+
"hash": "",
232+
"location": Object {
233+
"key": "345678",
234+
"pathname": "/first",
235+
"scene": "",
236+
"search": "",
237+
"url": "/first",
238+
},
239+
"params": Object {},
240+
"query": Object {},
241+
"state": Object {},
242+
"type": "FIRST",
243+
},
229244
],
230245
"from": null,
231-
"index": 0,
246+
"index": 2,
232247
"key": "345678",
233-
"kind": "back",
234-
"length": 2,
235-
"n": -1,
248+
"kind": "push",
249+
"length": 3,
250+
"n": 1,
236251
"pathname": "/first",
237252
"pop": false,
238253
"prev": Object {
@@ -276,7 +291,7 @@ Object {
276291
"location": Object {
277292
"basename": "",
278293
"blocked": null,
279-
"direction": "backward",
294+
"direction": "forward",
280295
"entries": Array [
281296
Object {
282297
"basename": "",
@@ -308,14 +323,29 @@ Object {
308323
"state": Object {},
309324
"type": "SECOND",
310325
},
326+
Object {
327+
"basename": "",
328+
"hash": "",
329+
"location": Object {
330+
"key": "345678",
331+
"pathname": "/first",
332+
"scene": "",
333+
"search": "",
334+
"url": "/first",
335+
},
336+
"params": Object {},
337+
"query": Object {},
338+
"state": Object {},
339+
"type": "FIRST",
340+
},
311341
],
312342
"from": null,
313343
"hash": "",
314-
"index": 0,
344+
"index": 2,
315345
"key": "345678",
316-
"kind": "back",
317-
"length": 2,
318-
"n": -1,
346+
"kind": "push",
347+
"length": 3,
348+
"n": 1,
319349
"params": Object {},
320350
"pathname": "/first",
321351
"pop": false,

0 commit comments

Comments
 (0)