I've been learning React along with Redux, and have noticed two ways to change the URL programmatically (not using ) when using React-Router.
One way is to push directly to browserHistory
.
import React from 'react';
import { browserHistory } from 'react-router';
class Name extends React.Component {
gotoPage() {
browserHistory.push('/page');
}
render() {
return Hello
}
}
The other is to push to this.context.router
.
import React, { PropTypes } from 'react';
import { browserHistory } from 'react-router';
class Name extends React.Component {
static contextTypes = {
router: PropTypes.object
};
gotoPage() {
this.context.router.push('/page');
}
render() {
return Hello
}
}
Should I use one over the other?
No comments:
Post a Comment