0

I am novice on react and I try to create a new website using react. and I have a problem with making button to switch to an other page. this is my code

import React from 'react';

export default class Connexion extends React.Component {

goToApp = event => {
    event.preventDefault();
    // On récupère le pseudo
    const pseudo = this.boxInput.value;
    // On change d'url
    this.context.router.transitionTo(`/box/${pseudo}`);
};

render() {
    return (
        <div className="connexionBox">
            <form className="connexion" onSubmit={(e) => this.goToApp(e)}>
                <h1>Connexion</h1>
                <input type="text" placeholder="Nom" pattern="[A-Za-z-]{1,}" required ref={(input) => {
                    this.boxInput = input
                }}/>
                <button type="submit">GO</button>
                <p>Pas de caractères spéciaux.</p>
            </form>
        </div>
    )
}
static contextTypes = {
    router: React.PropTypes.object
};}

and the erreur message is _this.context.router.transitionTo is not a function

thanks for your time

victor

PS: I do not use redux or anything like it.

3
  • are you using react-router? if so, what version? Commented Nov 30, 2017 at 14:09
  • on my index.js i use react-router-dom. but I add react-router 4.0.0-alpha.3 Commented Nov 30, 2017 at 14:11
  • this is not a duplicate of Unable to access React instance (this) inside event handler because the arrow function notation is being used in class definition, which appropriately binds this. Commented Nov 30, 2017 at 14:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.