react-router-last-location-17
v2.0.4
Published
Provides access to the last location in react + react-router (v4.x) apps. Useful for handling internal routing. Easily prevent leaving your app by users.
Downloads
185
Maintainers
Readme
react-router-last-location-17
Original
This is just a copy to fix peer dependency issues
- Provides access to the last location in
react
+react-router (v4.x, v5.x)
applications. - ❤️ Using
hooks
? If yes,useLastLocation
. - 💉 Using
HOC
? - If yes,withLastLocation
. - Handle redirects.
- Support
- Useful for handling internal routing.
- Easily keep your users inside your app.
Note: Last location != Previous browser history state
This library only returns the location that was active right before the recent location change, during the lifetime of the current window.
This means, it is not equal to the "location you were at before navigating to this history state".
In other words, the location this library provides is not necessarily the same as the one when you click the browser's back button.
Example 1
- Visit
/
: last location =null
, previous browser history state =null
- Visit
/a
: last location =/
, previous browser history state =/
- Visit
/b
: last location =/a
, previous browser history state =/a
- Reload (url will stay at
/b
): last location =null
, previous browser history state =/a
Example 2
- Visit
/
: last location =null
- Visit
/a
: last location =/
- Visit
/b
: last location =/a
- Go back: last location =
/b
, previous browser history state =/
Example 3
- Visit
/
: last location =null
- Visit
/a
: last location =/
- Visit
/b
: last location =/a
- Visit
/c
: last location =/b
- Go back to
/a
(by selecting that state explicitly in "Go back" browser dropdown that is visible upon clicking it with right mouse button): last location =/c
, previous browser history state =/
How to use?
# Please remember that you should have installed react, prop-types and react-router-dom packages
# npm install react prop-types react-router-dom --save
npm install react-router-last-location-17 --save