-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat($onBeforeChange): short-circuit redirecting + refactor middlewar…
…eCreateNotFoundAction + tests
- Loading branch information
1 parent
919d913
commit 0d23436
Showing
7 changed files
with
187 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// @flow | ||
import type { Location, Action, LocationState, History } from '../flow-types' | ||
import nestAction from '../pure-utils/nestAction' | ||
import { NOT_FOUND } from '../index' | ||
|
||
export default ( | ||
action: Object, | ||
location: LocationState, | ||
prevLocation: Location, | ||
history: History, | ||
notFoundPath: string | ||
): Action => { | ||
const { payload } = action | ||
|
||
const meta = action.meta | ||
const prevPath = location.pathname | ||
const kind = | ||
(meta && meta.location && meta.location.kind) || // use case: kind === 'redirect' | ||
(location.kind === 'load' && 'load') || | ||
'push' | ||
const pathname = | ||
(meta && meta.notFoundPath) || | ||
(kind === 'redirect' && notFoundPath) || | ||
prevPath || | ||
'/' | ||
|
||
return nestAction( | ||
pathname, | ||
{ type: NOT_FOUND, payload }, | ||
prevLocation, | ||
history, | ||
kind | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters