Coder Social home page Coder Social logo

Comments (8)

andreypopp avatar andreypopp commented on May 29, 2024

If you have a reference to a router, you can just do router.navigate('/sessions/new'). You can acquire a reference to a router via refs.

from react-router-component.

polmiro avatar polmiro commented on May 29, 2024

Does this mean I have to propagate this router throughout all components? Any workaround if I just have a global router?

from react-router-component.

andreypopp avatar andreypopp commented on May 29, 2024

Yes, you can mixin NaviagatableMixin and use this.navigate(path) method:

var Component = React.createClass({
  mixins: [require('react-router-component/lib/NavigatableMixin')],

  redirect: function() {
    this.navigate('/sessions/new')
  },

  ...
})

Component should be created inside one of route handlers. But even that requirement could be removed if you use routing environment directly. See how Link component is implemented — https://github.com/andreypopp/react-router-component/blob/master/lib/Link.js#L64

from react-router-component.

polmiro avatar polmiro commented on May 29, 2024

Great, thanks for the clarifications.

from react-router-component.

andreypopp avatar andreypopp commented on May 29, 2024

@polmiro do you think we can close this issue?

from react-router-component.

polmiro avatar polmiro commented on May 29, 2024

Yes, I also realized you are working on QuerystringKeyEnvironment for 0.16.0. I think it's going to be exactly what I need 👍

from react-router-component.

andreypopp avatar andreypopp commented on May 29, 2024

@polmiro yeah, QuerystringKeyEnvironment is alrady there but undocumented and doesn't support server side rendering yet.

from react-router-component.

saidimu avatar saidimu commented on May 29, 2024

For anyone else looking to redirect, here's a gist of a simple component that I use: https://gist.github.com/saidimu/2758402f7916f4e35dee

// jshint unused:true
var React = require('react');

var NavigatableMixin = require('react-router-component').NavigatableMixin;

var Redirect = React.createClass({
  mixins: [NavigatableMixin],

  _redirect: function(url) {
    this.navigate(url);
  },

  propTypes: {
    url: React.PropTypes.string.isRequired,
  },

  componentDidMount: function() {
    console.log('Redirecting to %s: ', this.props.url);
    this._redirect(this.props.url);
  },

  render: function() {
    return null;
  }
});//Redirect

module.exports = Redirect;

from react-router-component.

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.