forked from remix-run/react-router
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[changed] Transition#cancelReason => abortReason
Also, transition.abort() now accepts a reason argument that indicates the reason for the abort. I anticipate that we'll need to add a NotFound reason soon.
- Loading branch information
Showing
3 changed files
with
58 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Encapsulates a redirect to the given route. | ||
*/ | ||
function Redirect(to, params, query) { | ||
this.to = to; | ||
this.params = params; | ||
this.query = query; | ||
} | ||
|
||
module.exports = Redirect; |
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 @@ | ||
var copyProperties = require('react/lib/copyProperties'); | ||
var transitionTo = require('./transitionTo'); | ||
var Redirect = require('./Redirect'); | ||
|
||
/** | ||
* Encapsulates a transition to a given path. | ||
* | ||
* The willTransitionTo and willTransitionFrom handlers receive | ||
* an instance of this class as their first argument. | ||
*/ | ||
function Transition(path) { | ||
this.path = path; | ||
this.abortReason = null; | ||
this.isAborted = false; | ||
} | ||
|
||
copyProperties(Transition.prototype, { | ||
|
||
abort: function (reason) { | ||
this.abortReason = reason; | ||
this.isAborted = true; | ||
}, | ||
|
||
redirect: function (to, params, query) { | ||
this.abort(new Redirect(to, params, query)); | ||
}, | ||
|
||
retry: function () { | ||
transitionTo(this.path); | ||
} | ||
|
||
}); | ||
|
||
module.exports = Transition; |