我们假设我在路由中使用以下结构:
var React = require('react');
var Router = require('react-router');
var Route = Router.Route;
var DefaultRoute = Router.DefaultRoute;
var App = require('../components/App'),
About = require('../components/About'),
Home = require('../components/Home');
var routes = (
<Route name="app" path="/" handler={App}>
<Route path="about" name="about" handler={About} />
<DefaultRoute name="home" handler={Home} />
</Route>
);
module.exports = routes;
home
组件如下所示:
var React = require('react');
var loginStore = require('../stores/LoginStore');
var Home = React.createClass({
displayName: 'Home',
propTypes: {},
statics: {
willTransitionTo(transition) {
console.log('HEREEEEEEEE');
if (!loginStore.isLoggedIn()) {
loginStore.setTransitionPath(transition.path);
transition.redirect('login');
}
}
},
render: function() {
return (<div>
</div>);
}
});
module.exports = Home;
假设用户想要路由到/about
,虽然我们希望home
不会生效,但我们会在屏幕上显示console.lo
g结果,这意味着{{1家里正在运行。这是一个错误还是我错过了什么?