Matthew Herbst
Matthew Herbst

Reputation: 31963

React-Router send user to another route

Let's say the user has to enter some text into a box, and if the text matches a certain pattern, I send them to another route. How do I do that?

I've been trying to do:

import React from 'react';
import { Navigation } from 'react-router';

React.createClass({
  mixins: [Navigation],
  handleChange () {
     if(...) {
       this.transitionTo('someRoute', {id: 10});
     }
  },
  render () {
    <input ... onChange={this.handleChange} >
  }
});

However, I keep getting the error:

Uncaught TypeError: this.transitionTo is not a function

I can't find anything clear in the docs, and the example above is taken from a random link I found while Googling. What am I missing/doing incorrect? I'm using react-router v1.0.3

Upvotes: 1

Views: 157

Answers (1)

Nathan
Nathan

Reputation: 26

What version of react router are you on?

Mixin's have more or less been abandoned by react. In react-router 1.0.0 ideally the way you would accomplish a redirect is by using history.pushState.

The rackt team has also just recently released an rc version for 2.0.0. Looks like you'll now need to manually include the history in your router instance - but it's not too different. Check out the upgrade guide

Upvotes: 1

Related Questions