Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion lib/components/AuthorizedComponent.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as roleMatcher from '../utils/roleMatcher';

class AuthorizedComponent extends React.Component {
static propTypes = {
location: PropTypes.object.isRequired,
routes: PropTypes.array.isRequired
};

Expand All @@ -24,8 +25,22 @@ class AuthorizedComponent extends React.Component {
// validate properties first
this.validate();

this.checkRoles(this.props);
}

componentWillUpdate(nextProps) {
// skip if change props in same route
if (this.props.location.pathname === nextProps.location.pathname) {
return;
}

this.checkRoles(nextProps);
}

// check permission
checkRoles(props) {
// when you use react-router, `routes` should be set
const { routes } = this.props;
const { routes } = props;

// check roles
const routeRoles = roleMatcher.getFlatterRoles(routes);
Expand Down