gpt4 book ai didi

javascript - React-Router 使用 jQuery 浏览路由

转载 作者:行者123 更新时间:2023-12-03 05:37:38 25 4
gpt4 key购买 nike

好吧,我的 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
*/
}
);

任何想法将不胜感激。谢谢:)

最佳答案

一种方法如下:

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");
}
);

关于javascript - React-Router 使用 jQuery 浏览路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40667369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com