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.
The router now remembers the last window scroll position at various paths and automatically scrolls the window to match after transitions complete unless preserveScrollPosition=true is used. This commit also introduces a flux-style architecture to the high-level transitionTo/replaceWith/goBack methods. Fixes remix-run#189 Fixes remix-run#186
- Loading branch information
Showing
15 changed files
with
162 additions
and
80 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
module.exports = require('./modules/helpers/goBack'); | ||
module.exports = require('./modules/actions/LocationActions').goBack; |
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,57 @@ | ||
var LocationDispatcher = require('../dispatchers/LocationDispatcher'); | ||
var makePath = require('../helpers/makePath'); | ||
|
||
/** | ||
* Actions that modify the URL. | ||
*/ | ||
var LocationActions = { | ||
|
||
PUSH: 'push', | ||
REPLACE: 'replace', | ||
POP: 'pop', | ||
UPDATE_SCROLL: 'update-scroll', | ||
|
||
/** | ||
* Transitions to the URL specified in the arguments by pushing | ||
* a new URL onto the history stack. | ||
*/ | ||
transitionTo: function (to, params, query) { | ||
LocationDispatcher.handleViewAction({ | ||
type: LocationActions.PUSH, | ||
path: makePath(to, params, query) | ||
}); | ||
}, | ||
|
||
/** | ||
* Transitions to the URL specified in the arguments by replacing | ||
* the current URL in the history stack. | ||
*/ | ||
replaceWith: function (to, params, query) { | ||
LocationDispatcher.handleViewAction({ | ||
type: LocationActions.REPLACE, | ||
path: makePath(to, params, query) | ||
}); | ||
}, | ||
|
||
/** | ||
* Transitions to the previous URL. | ||
*/ | ||
goBack: function () { | ||
LocationDispatcher.handleViewAction({ | ||
type: LocationActions.POP | ||
}); | ||
}, | ||
|
||
/** | ||
* Updates the window's scroll position to the last known position | ||
* for the current URL path. | ||
*/ | ||
updateScroll: function () { | ||
LocationDispatcher.handleViewAction({ | ||
type: LocationActions.UPDATE_SCROLL | ||
}); | ||
} | ||
|
||
}; | ||
|
||
module.exports = LocationActions; |
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,18 @@ | ||
var copyProperties = require('react/lib/copyProperties'); | ||
var Dispatcher = require('react-dispatcher'); | ||
|
||
/** | ||
* Dispatches actions that modify the URL. | ||
*/ | ||
var LocationDispatcher = copyProperties(new Dispatcher, { | ||
|
||
handleViewAction: function (action) { | ||
this.dispatch({ | ||
source: 'VIEW_ACTION', | ||
action: action | ||
}); | ||
} | ||
|
||
}); | ||
|
||
module.exports = LocationDispatcher; |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1 +1 @@ | ||
module.exports = require('./modules/helpers/replaceWith'); | ||
module.exports = require('./modules/actions/LocationActions').replaceWith; |
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 |
---|---|---|
@@ -1 +1 @@ | ||
module.exports = require('./modules/helpers/transitionTo'); | ||
module.exports = require('./modules/actions/LocationActions').transitionTo; |