[英]React-Router Navigating Through Routes Using jQuery
Ok, I have my React-Router working more or less the way I want it but my issue is this: I now need to add a bit of functionality in my JS. 好的,我的React-Router或多或少都按照我想要的方式工作,但是我的问题是:我现在需要在JS中添加一些功能。
Example: The user enters their details and clicks 'login', I would like my jQuery to check if the credentials are correct and if they are change the route to the home page. 示例:用户输入他们的详细信息并单击“登录”,我希望我的jQuery检查凭据是否正确以及它们是否更改了到主页的路径。
I have no idea, how I would go about this. 我不知道该怎么办。
This is my React-Router code: 这是我的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
*/
}
);
Any ideas would be greatly appreciated. 任何想法将不胜感激。 Thanks :)
谢谢 :)
One way would be the following: 一种方法如下:
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");
}
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.