Automatic redirect after login with react-router

React Router v3 This is what I do var Router = require(‘react-router’); Router.browserHistory.push(‘/somepath’); React Router v4 Now we can use the <Redirect>component in React Router v4. Rendering a <Redirect> will navigate to a new location. The new location will override the current location in the history stack, like server-side redirects. import React, { Component } … Read more

How to submit a form using Enter key in react.js?

Change <button type=”button” to <button type=”submit”. Remove the onClick. Instead do <form className=”commentForm” onSubmit={this.onFormSubmit}>. This should catch clicking the button and pressing the return key. const onFormSubmit = e => { e.preventDefault(); // send state to server with e.g. `window.fetch` } … <form onSubmit={onFormSubmit}> … <button type=”submit”>Submit</button> </form>

how to cancel/abort ajax request in axios

Axios does not support canceling requests at the moment. Please see this issue for details. UPDATE: Cancellation support was added in axios v0.15. EDIT: The axios cancel token API is based on the withdrawn cancelable promises proposal. UPDATE 2022: Starting from v0.22.0 Axios supports AbortController to cancel requests in fetch API way: Example: const controller … Read more