This repository has been archived by the owner on Sep 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: prevent the back button during transitions
Previously pressing the back button during transitions could cause the page to look glitchy or elements to dissapear. This prevents that.
- Loading branch information
Tyler Barnes
committed
Mar 25, 2019
1 parent
7a5b683
commit f879140
Showing
3 changed files
with
32 additions
and
10 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 |
---|---|---|
@@ -1,3 +1,16 @@ | ||
const { navigate } = require("gatsby"); | ||
|
||
exports.wrapPageElement = require(`./wrap-page`); | ||
|
||
exports.shouldUpdateScroll = () => false; | ||
|
||
exports.onPreRouteUpdate = ({ location }) => { | ||
// prevent the back button during transitions as it breaks pages | ||
if ( | ||
window.__tl_inTransition && | ||
location.pathname !== window.__tl_desiredPathname | ||
) { | ||
window.__tl_back_button_pressed = true; | ||
navigate(window.__tl_desiredPathname); | ||
} | ||
}; |
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