我在登录并验证后尝试进入用户视图/状态,但似乎无法让路由器做反应。
App的初始状态只是一个静态导航栏,其中的视图可以正常路由,但是当用户登录或进行身份验证时,我不确定该怎么做。我是否更改导航栏的状态并专门为用户登录状态创建新的响应路由器?
我认为我还不需要使用助焊剂,因为不需要存储数据(用户数据除外)?
这是路线的样子:
// React
var React = require("react");
var Router = require("react-router");
var Route = Router.Route;
var NotFoundRoute = Router.NotFoundRoute;
var DefaultRoute = Router.DefaultRoute;
var App = require('./components/App.js');
var About = require('./components/About.js');
var Concat = require('./components/Concat.js');
var Home = require('./components/Home.js');
var Landing = require('./components/Landing.js');
var Login = require('./components/Login.js');
var Search = require('./components/Search');
var Signup = require('./components/Signup');
var routes = (
<Route path="/" handler={App}>
<DefaultRoute handler={Landing} />
<Route name="about" path='/about' handler={About}/>
<Route name="concat" path='/concat' handler={Concat}/>
<Route name="home" path='/home' handler={Home}/>
<Route name="login" path='/login' handler={Login}/>
<Route name="search" path='/search' handler={Search}/>
<Route name="signup" path='/signup' handler={Signup}/>
</Route>
);
module.exports = routes;
这是Navbar:
var React = require('react');
var Router = require('react-router');
var Link = Router.Link;
var Navbar = React.createClass({
render: function () {
return (
<div className="navbar navbar-default navbar-static-top">
<div className="container">
<div className="navbar-header">
<button type="button" className="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span className="icon-bar">test</span>
<span className="icon-bar"></span>
<span className="icon-bar"></span>
</button>
</div>
<div className="collapse navbar-collapse">
<ul className="nav navbar-nav">
<li className="active"><Link to="home">Jobletics</Link></li>
<li><Link to="concat">Create a Listing</Link></li>
<li><Link to="search">Search Jobs</Link></li>
<li><Link to="about">About</Link></li>
</ul>
<ul className="nav navbar-nav navbar-right">
<li><Link to="login">Log in</Link></li>
<li><Link to="signup">Sign up</Link></li>
</ul>
</div>
</div>
</div>
);
}
});
module.exports = Navbar;
思想?
答案 0 :(得分:2)
There are a couple things that you still need to do. You don't need flux here but you do need a little bit of state handling. Here is a link to an older commit/explanation of authentication flow from react-router.
The reason I posted an older commit is that the most updated ones are using es6 and even an unreleased version I believe. This link should work just fine your cause, though.