- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我是 React/redux 的新手。我有一个用于身份验证的 Redux 操作,之后我需要重定向到一个确认页面主页。我不知道如何重定向
这是我的 index.js
import React, { PropTypes } from 'react';
import { connect } from 'react-redux';
import { FormattedMessage } from 'react-intl';
import { createStructuredSelector } from 'reselect';
import {loginAction} from './actions';
export class Login extends React.PureComponent { // eslint-disable-line react/prefer-stateless-function
constructor(props) {
super(props);
this.state = {
username: '',
password: ''
};
// this.handleChange = this.handleChangeUsername.bind(this);
// this.handleSubmit = this.handleChangePassword.bind(this);
}
handleChangeUsername(event) {
console.log(event.target.value);
this.setState({username: event.target.value});
console.log(this.state.username)
}
handleChangePassword(event) {
this.setState({password: event.target.value});
console.log(this.state.password)
}
handleSubmit(event) {
this.props.dispatch(loginAction(this.state));
event.preventDefault();
}
render() {
return (
<div>
<div className="loginColumns animated fadeInDown">
<div className="row">
<div className="col-md-6">
</div>
<div className="col-md-6">
<div className="ibox-content">
<form className="m-t" role="form" onSubmit={this.handleSubmit.bind(this)}>
<div className="form-group">
<input type="email" value={this.state.username} onChange={this.handleChangeUsername.bind(this)} className="form-control" placeholder="Username" required="" />
</div>
<div className="form-group">
<input type="password" value={this.state.password} onChange={this.handleChangePassword.bind(this)} className="form-control" placeholder="Password" required="" />
</div>
<button type="submit" className="btn btn-primary block full-width m-b">Login</button>
<a href="#">
<small>Forgot password?</small>
</a>
</form>
</div>
</div>
</div>
<hr/>
<div className="row">
<div className="col-md-6">
Copyright Example Company
</div>
<div className="col-md-6 text-right">
<small>© 2014-2015</small>
</div>
</div>
</div>
</div>
);
}
}
Login.propTypes = {
dispatch: PropTypes.func.isRequired,
};
const mapStateToProps = createStructuredSelector({
// Login: makeSelectLogin(),
});
function mapDispatchToProps(dispatch) {
return {
dispatch,
};
}
export default connect(mapStateToProps, mapDispatchToProps)(Login);
Action .js
import {
DEFAULT_ACTION,
LOGIN_ACTION
} from './constants';
export function defaultAction() {
return {
type: DEFAULT_ACTION,
};
}
export function loginAction(json) {
return {
type: LOGIN_ACTION,
json
};
}
reducer.js
import { fromJS } from 'immutable';
import {
DEFAULT_ACTION,
LOGIN_ACTION
} from './constants';
const initialState = fromJS({
status: false
});
function loginReducer(state = initialState, action) {
console.log("action", action)
switch (action.type) {
case DEFAULT_ACTION:
return state;
case LOGIN_ACTION:
return _testFunction(state,action.json);
default:
return state;
}
}
function _testFunction(state, json) {
if(json.username == "abcd@gmail.com" && json.password == "1234")
return state.set("status", true)
}
export default loginReducer;
我想在成功登录后重定向/home。我该如何重定向?
最佳答案
嗯,你要做的就是这样的事情。将回调传递给您的操作。一旦操作完成,它就会工作,只需调用该回调,它将以编程方式将您重定向到您需要的 url。提交登录表单后,将带有回调函数的输入值传递给您的操作,就像这样。
onSubmit(values) {
this.props.loginAction(values, () => {
this.props.history.push('/');
});
}
然后在您的操作中,如果您正在调用后端 API,当 promise 被解析时,确保您调用像这样传递给操作的回调函数。
export function loginAction(values, callback) {
const request = axios.post(`/endpoint`, values)
.then(() => callback());
return {
type: LOGIN,
payload: request
};
}
这就是您要做的全部。您可以根据您的场景和设置对此进行细微改动。我会把它留给你作为练习。希望这可以帮助。快乐编码!
关于javascript - react /归零 : redirect after loggin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45012318/
我有一个使用 PHP 设置页面输入字段值的表单,例如: // create and fill inputVarsArr with keys that have empty vals $troubleI
大家好,我是码农先森。 古话说的 "三十而立",正是担重之时,却大部分人在职场中都处于不上不下的尴尬境地。已经没有刚毕业时那股子冲劲,被生活和工作磨平了棱角。 在技术思想方面,
我想将这个“.wrapper wf”类归零。 (比如 header 和 .p)但是我不能成功,你能帮我弄清楚吗? here is the fiddle .wf{ -webkit-transfo
这个问题在这里已经有了答案: 关闭 10 年前。 Possible Duplicate: Set all bytes of int to (unsigned char)0, guaranteed t
当使用STL容器时,我不确定默认分配器分配的一个int是否已经归零。以下代码对问题表示"is": #include #include int main() { using namespace
我有一个包含弱引用的对象的以下简单代码: //界面 @interface GMWeakRefObj : NSObject @property (weak) id object; @end //执行 @
我是 React/redux 的新手。我有一个用于身份验证的 Redux 操作,之后我需要重定向到一个确认页面主页。我不知道如何重定向 这是我的 index.js import React, { Pr
我有一个 vector我想把它归零。我需要尺寸保持不变。 通常的方法是遍历所有元素并重置它们。但是,vector是 specially optimized容器,根据实现,每个元素可能只存储一位。有没有
我错误地将密码存储为 Java 程序中的字符串。我想防止此字符串密码出现在堆转储/内存转储中。理想情况下,我应该使用 char[] 并在使用后将其填充为零(如本文 - https://nvisium.
是否 x.resize(1024)保证valarray x会归零吗? 是否std::valarray z(1024);保证它也将被填充为零? 对于 Mac、Windows 和 Linux 是这样吗?即
下面的 java 代码是否足以清除内存中的 key (将其所有字节值设置为 0)? zerorize(SecretKey key) { byte[] rawKey = key.getEncod
我是 React 和 Redux 的初学者,我正在尝试设置一个非常简单的登录表单和重定向。我稍后会添加 react-router 或 react-router-redux。 我真的不明白我必须在哪里放
最近我一直在使用 cgo 在我的一个项目中设置 libsodium,以便使用 crypto_pwhash_str 和 crypto_pwhash_str_verify 函数. 这一切都进行得非常顺利,
我正在使用以下代码从网站检索一些数据。 Public Function giveMeValue(ByVal link As String) As String Set htm = CreateO
我想要获得与在 Photoshop 中关闭其中一个 channel 相同的结果。我正打算尝试循环改变颜色的每个像素。有更好的方法吗? 最佳答案 使用 Core Image 的颜色矩阵滤镜。 The a
我有以下用于导航的组件: import React, { Component } from "react"; import { connect } from 'react-redux'; import
试图在 Redux-React-API 丛林的黑暗深处找到方向 - 设法从 API 和 console.log 中获取数据 - 但我和我的 Google 技能都无法找出它不呈现的原因。 react 组
在我使用 redux 的 native react 应用程序中,reducers 似乎工作正常,但 UI 不会根据状态修改进行更新。 这是我的 reducer : const initialState
这tutorial Dan Abramov 提出,使用作用于全局状态(而不是一部分状态)的选择器的优势在于它们允许容器与状态结构的知识分离。 如果是这样的话,我们不应该也避免直接将状态值映射到 Pro
背景 我正在构建一个包装程序包,它组合了定义的命令并允许它们在 cli 或交互式 shell 上下文中执行。命令在类似这样的结构中定义(显示相关字段): type Handler func(c *Co
我是一名优秀的程序员,十分优秀!