React-router redirection 'parent' url

react redirect to url onclick
react router params
react router example
react-router redirect with props
react router match
react-router link onclick
react redirect to external url
react router query params

I am struggling with something which looks really simple.

So lets say I have an url like this one

http://192.168.88.226:3000/test/a/hello

and I want to redirect to http://192.168.88.226:3000/test/b/hello

right now this is my code

import { Redirect } from 'react-router';
<Redirect to="b/hello" />

But I am getting http://192.168.88.226:3000/test/a/b/hello

I dont know how to redirect "on level up" and replace a

Thank you everybody

one thing you can do is :

 <Redirect to="/test/b/hello" />

Route, https://github.com › blob › master › packages › react-router › docs › api Redirecting in React Redirect Component. If you have routes in your React app, you’re probably using React Router (or React Router DOM) to Route Component Props. The Route component provides three props to whatever component it renders: location, match and Context and PropTypes. In order to

You can go to the parent component with:

<Redirect to="../b/hello" />

And you can get to subsequent parents like this:

<Redirect to="../../b/hello" />

and:

<Redirect to="../../../b/hello" />

But as you can see it gets messy if you are traversing a big tree of parent nodes.

React Router Redirect, Redirect Component. If you have routes in your React app, you're probably using React Router (or React Router DOM) to set up your routes. React-router 2.4.0 (April 2016) introduced withRouter which creates a HOC. However it wraps React.createClass, not a JS class. I haven't been able to get it working with redux-form, etc.

you can use

import { Router, Route, hashHistory } from 'react-router/lib';
<Router history={hashHistory}>
  <Route path="/b/hello" component={myB_HelloComponent} />
</Router>

but first you need to check your react-router's version

Redirecting in React - Annee Barrett, import { Redirect } from "react-router-dom";. The easiest way to use this method is by maintaining a redirect property inside the state of the  Now we can use the <Redirect>component in React Router v4. Rendering a <Redirect> will navigate to a new location. The new location will override the current location in the history stack, like server-side redirects.

React Router Redirect: Programmatic Navigation in React using , You have to use setState to set a property that will render the <Redirect> inside your render() method. E.g. class MyComponent extends React.Component  I am new to React Router and learn that there are so many ways to redirect a page: Using browserHistory.push ("/path") import { browserHistory } from 'react-router'; //do something browserHistory. Using this.context.router.push ("/path") class Foo extends React.Component { constructor(props,

How to use Redirect in the new react-router-dom of Reactjs, A <Redirect> sets up a redirect to another route in your application to maintain old URLs. Props. from. The path you want to redirect from, including dynamic  There are a few different approaches to redirecting with React Router. You can use the imperative history.push method or you can use the declarative <Redirect /> component. In this case, let’s go with <Redirect />. We’ll need to add a property to the component’s state that will clue us into when we should render a <Redirect />.

<Redirect> · React Router, Redirecting a page based on some condition is an usual need in a react web application. React router provides an easy way to achieve it. A <Redirect> sets up a redirect to another route in your application to maintain old URLs.

Comments
  • did any of the answers solve your issue? do you need more assistance with your problem?
  • But then I get 192.168.88.226:3000/test/a/test/b/hello so the thing is that the stuff I putt after to= is being attached after a/ instead after test/
  • You will not get a relative url if your url begins with a slash.