GithubHelp home page GithubHelp logo

Comments (3)

elboman avatar elboman commented on April 19, 2024 1

The best thing would be to get the previous state from the last transition and use that as target:

Inside a routed component you can access the transition via props:

  render () {
    let {transition} = this.props;

    // access the state we navigated from
    let prevState = transition.from();
    let prevParams = transition.params('from');

    // navigate to the state
    transition.router.stateService.go(prevState, prevParams);
  }

Since the router is synced with the browser history you can always navigate back using the DOM api:

window.history.back();

I guess it depends on what you need to achieve.

The first method is useful for handling redirects inside the application. In the sample app we redirect users that are not logged in to the log in page. Once the user has logged we find out which state triggered the original redirect and redirect the user back to that state (you can see here what I'm trying to explain).

Glad to help! Let me know if you have any more doubts!

from react.

MarcoPortillo avatar MarcoPortillo commented on April 19, 2024

@elboman Hi, thanks for the explanation.

It didn't work for me, nothing happens if I apply this. Using the DOM api is not an option for me, aren't there any other ways to go back? The documentation says nothing about it.

from react.

yofret avatar yofret commented on April 19, 2024

Oh Wow, I never replied to this thread, It did work for me when I was using it! I never gave a proper thanks!

from react.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.