-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to retrieve the last match
object
#38
Comments
Hey @Nogias9x |
Thank you @hinok, |
HI @hinok , Thank you so much |
@Nogias9x There is no written instruction at the moment but it's quite straightforward in my opinion.
which is useful to write tests with watch mode. |
I'm not smart enough to know how to build this, but I want this too. I want to know which component this link came from, and it'd be easiest to look at the last route and pass that to useMatch... but it doesn't seem like you can tell useMatch to operate on something other than the current location? |
@xaphod You can use matchPath(lastLocation.pathname, path) Demo: https://codesandbox.io/s/using-matchpath-with-lastlocation-urlvo
Code import * as React from "react";
import { matchPath } from "react-router-dom";
import {
withLastLocation,
WithLastLocationProps
} from "react-router-last-location";
const About: React.FC<WithLastLocationProps> = ({ lastLocation }) => (
<div>
<h1>About! {lastLocation && lastLocation.pathname}</h1>
<h2>Your last location</h2>
<pre>{JSON.stringify(lastLocation, undefined, 2)}</pre>
<h2>Came from contact?</h2>
<pre>
{lastLocation && matchPath(lastLocation.pathname, "/contact")
? "Yes"
: "No"}
</pre>
</div>
);
export default withLastLocation(About); Unfortunately you have to pass a specific |
Hello everybody,
Is there any way I could retrieve the last
match
({path, url})?I want to know which is the matched route (likes "/users/:userId/cart") of the last location, so I can know what is the matched page of the last location.
Thank you for your time
The text was updated successfully, but these errors were encountered: