Reputation: 44
When i am clicking on the link(having key containing auth token) which i am getting in my mail,it is redirecting me to Update password page.But I don't want to redirect it if a user is just entering the URL.
[http://localhost:3000/update-password?key=ZXlKaGJHY2lPaUpJVXpJMU5pSXNJblI1Y0NJNklrcFh] should redirect to Change Password page and [http://localhost:3000/update-password] should redirect to PageNotFound page.i hope you'll understand.
Upvotes: 0
Views: 38
Reputation: 1168
You should follow three steps:
Get current search
from react-router
:
const {
location: { search }
} = propsFromReactRouter
Check, does search
contain key. You can do it with https://www.npmjs.com/package/query-string on mannualy.
import { parse } from 'query-string';
const searchData = parse(search);
const { key } = searchData;
if search doesn't contain key, redirect to not found page
import {Redirect} from 'react-router-dom'
// ...
return (
<Redirect to="/404" />
)
Upvotes: 1