|
Download wp-calypso/client/lib/detect-history-navigation/README.md from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.06 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/lib/detect-history-navigation/README.md
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/lib/detect-history-navigation/README.md
-
curl -L -o README.md https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/lib/detect-history-navigation/README.md
1.06 kB
| # detect-history-navigation | |
| This module determines when a page has been rendered via the history event (back or forward buttons, or via the history methods) versus being a newly navigated page (e.g., via clicking a link to a page). | |
| This can be used alongside the [Calypso Router module](../../../packages/calypso-router) by calling the `start()` method of this module _prior_ to the `start()` method of `page.js`. | |
| ```js | |
| import page from '@automattic/calypso-router'; | |
| import detectHistoryNavigation from 'detect-history-navigation'; | |
| detectHistoryNavigation.start(); | |
| page.start(); | |
| ``` | |
| Then controllers and components can call `detectHistoryNavigation.loadedViaHistory()` which returns a boolean determining whether the current route is being loaded from a history event or is a fresh pageload. | |
| Components that are mounted into the initial view of a page that is loaded by history can detect this in `componentWillMount`, `componentDidMount`, and the initial run of their `render` method. After the initial render `loadedViaHistory()` will return false. | |