George Mauer George Mauer - 1 year ago 492
React JSX Question

Programmatically navigate using react router


I can use the
element to create links that are natively handled by react router.

I see internally it calls

I want to do a navigation, but not from a link, from a dropdown selection for example. How can I do this in code? What is

I saw the
mixin, but can I do this without mixins?

Answer Source

for the most recent release (v2.0.0-rc5), the recommended navigation method is by directly pushing onto the history singleton. You can see that in action here. Relevant excerpt:

import { browserHistory } from './react-router'

If using the newer react-router API, you need to make use of the history from this.props when inside of components so:


It also offers pushState but that is deprecated per logged warnings.

If using react-router-redux, it offers a push function you can dispatch like so:

import { push } from 'react-router-redux';

However this may be only to change the URL not actually navigate to the page.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download