react-router icon indicating copy to clipboard operation
react-router copied to clipboard

This example code makes no sense to me

Open 0x80 opened this issue 11 years ago • 3 comments

var Navigation = require('react-router').Navigation;

React.createClass({
  mixins: [Navigation],

  whenever: function () {
    this.transitionTo('something');
    this.replaceWith('something');
    this.goBack();
  }
});

From reading the docs I just don't understand how this makes any sense. Could you maybe explain a bit more what's happening here? Thanks :)

0x80 avatar Feb 03 '15 10:02 0x80

Looks like someone was too lazy to come up with a real example :smile:

It just tells you that with Navigation mixin you get to use this three methods on the component instance. Usually, you'd call them from a handler method, like a click handler. You should only call one of those at a time though. Perhaps this makes more sense:

var Navigation = require('react-router').Navigation;

React.createClass({
  mixins: [Navigation],

  render: function() {
    return (
      <div onClick={() => this.transitionTo('foo')}>Go to foo</div>
      <div onClick={() => this.replaceWith('bar')}>Go to bar without creating  a new history entry</div>
      <div onClick={() => this.goBack()}>Go back</div>
    );
  }
});

agundermann avatar Feb 03 '15 11:02 agundermann

Phew I thought I was loosing it. Your example is how I understood the text :smile:

0x80 avatar Feb 03 '15 11:02 0x80

Feel free to update the example, sometimes its 1:00am and I've been writing docs/upgrade guides for hours at that point and don't give it enough thought :)

ryanflorence avatar Feb 04 '15 18:02 ryanflorence