New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refresh current route in react-router #2097
Comments
It's just React. If you want a component to re-render in React, you set some state. So if you want one of your route components to re-render, use |
@mjackson actually I'm talking about whole page, not component. So I need to write custom link class, i.e.:
and check
something like that? |
@paveleremin I think you have to change state on the root component, once you will do that - you will see an updated route. That's the right way of doing things in react. |
it's easy, you can cutomized RouteLink capture the link state and attach onClick event to if (this.props.refresh === true) window.location.href ='xxxx'; import React from 'react';
import { Link, History } from 'react-router';
import URI from '../../utils/URI';
const RouteLink = React.createClass({
mixins:[History],
getDefaultProps() {
return {
refresh: false
}
},
getPropTypes() {
return {
// for refresh page, the whole page reload.
refresh: React.PropTypes.bool,
// cutomized regex match to test if current RouteLink is `active` state.
match: React.PropTypes.string
};
},
handLinkClick (e) {
if (this.props.refresh === true) {
window.location.href = e.target.href;
}
},
render () {
// Note there is an bug in ie <=11, this.history is undefined.
// the mixin has some problem in windows <IE10 use ES5 instead.
let { to, match } = this.props;
let isActive;
let currentURL = window.location.href;
let currentHash = currentURL.replace(URI.getUrl(), '/');
if (match) {
let regExpStr = match.replace(/\//g,'\/');
isActive = new RegExp(regExpStr).test(currentHash);
} else {
isActive = this.history.isActive(to, this.props.query);
}
let className = isActive ? 'active' : '';
return (
<li className={className}><Link onClick={this.handLinkClick.bind(this)} {...this.props} activeClassName={null} /></li>
);
}
});
module.exports = RouteLink; the example in your components: <RouteLink refresh={true} match="^\/(docs\/|docs)?$" activeClassName="active" to="/docs">RUI Docs</RouteLink> |
BTW, i don't know if |
Is it posible to refresh current route in react-router by pressing the same url? For example, in angularjs with ngroute you can write href="/dasboard/" instead of href="/dashboard". With ui-route it work out of the box. And what about react with react-router?
I.e. I want that the dashboard can be refresh by click at the top menu(user repeat the click at the active menu element and the page refresh)
something like that
The text was updated successfully, but these errors were encountered: