好的,我的React-Router或多或少都按照我想要的方式工作但我的问题是:我现在需要在我的JS中添加一些功能。
示例:用户输入详细信息并点击“登录”,我希望我的jQuery检查凭据是否正确以及是否更改了到主页的路径。
我不知道,我怎么会这样做。
这是我的React-Router代码:
import React from 'react'
import ReactDOM from 'react-dom';
import { Router, Route, hashHistory, Navigation } from 'react-router'
import Login from './login'
import Signup from './signup'
import Home from './home'
ReactDOM.render((
<Router history={hashHistory}>
<Route path="/" component={Login}/>
<Route path="/signup" component={Signup}/>
<Route path="/home" component={Home}/>
</Router>
), document.getElementById("app"))
$("#loginBtn").click(
function(){
var email = $('loginEmail').val();
var pass = $('loginpwd').val();
/* Check to see if credential are correct.
* If so, change to '/home route
*/
}
);
任何想法都将不胜感激。谢谢:))
答案 0 :(得分:1)
一种方法如下:
const openAppRoute = (route) => {
// Summary:
// Helper function for developers to navigation
// to a different route programmatically.
hashHistory.push(route);
};
window.openAppRoute = openAppRoute;
$("#loginBtn").click(
function(){
var email = $('loginEmail').val();
var pass = $('loginpwd').val();
/* Check to see if credential are correct.
* If so, change to '/home route
*/
window.openAppRoute("/home");
}
);