0

I have a react app uses react-router to route between pages. The problem is this: I'm in a page in the following route: http://example.com/my-current-location/ and I want to route to http://example.com/my-next-location/

I tries using

this.props.history.push("/my-next-location")

but that takes my to http://example.com/my-current-location/my-next-location/ which is not what I need.

this.props.history.push("/my-next-location")

What I need is a way to navigate to absolute path. Of course,

location.replace()

won't do since I don't want a full page refresh. How can I achieve this?

Sig
  • 93
  • 1
  • 1
  • 5
  • Hi. Do you have the paths declared on your main react-router component? If you do it will be just a matter if using a `` in the place you want the linking button. Cheers! – Rafael Mora Oct 13 '19 at 12:29
  • check this link [How to use Redirect in the new react-router-dom of Reactjs](https://stackoverflow.com/questions/43230194/how-to-use-redirect-in-the-new-react-router-dom-of-reactjs) – i am davood Oct 13 '19 at 12:57

1 Answers1

0

you can use <Link /> or this component

import React from 'react;
import {Redirect} from "react-router-dom";




/**
 * @param {boolean} props.redirect 
 */

const index = props =>{

return props.redirect ? 
<Redirect to="/my-next-location" />
:<div>
   the components code
</div>

}

i am davood
  • 175
  • 15