首先项目有自己的路由,然后我在开打登录界面的时候,ajax请求后端验证,成功后跳转路由,这里就会产生问题,求指导
路由配置:
import { Router, Route, Link, hashHistory,useRouterHistory, IndexRoute } from 'react-router';
import { createHistory } from 'history';
const appHistory = useRouterHistory(createHistory)({
basename: WP_BASE_HREF
})
<Router history={appHistory}>。。。。。。</Router>
登录验证:
$.ajax({
url:'/api/login',
type: 'POST',
dataType: 'json',
data: {
name: Email,
password: Password
},
success: function(map){
var login = map.error;
if (!login) {
appHistory.transitionTo('/index');//路径会加上index但是页面不跳转
// window.localtion.href()//页面会刷新,不想使用
// hashHistory.push('/index');//之前用hashHistory这种方法,后来有一些bug就不用次方方法了
}else{
$("#errorBtn").click();
}
}
})
目前想使用appHistory这个方法,我想知道有什么办法能让他跳转。或者有其他的办法也可以
控制台打印的appHistory:
createHref:function createHref(location)
createKey:function createKey()
createLocation:function createLocation(location)
createPath:function createPath(location)
getCurrentLocation:function getCurrentLocation()
go:function go(n)
goBack:function goBack()
goForward:function goForward()
listen:function listen(listener)
listenBefore:function listenBefore(hook)
push:function push(location)
replace:function replace(location)
transitionTo:function transitionTo(nextLocation)
__proto__:Object
使用push等方法都是路径变为/index但是页面不会路由过去
你可以包装
Route
,把认证页面换成AuthRoute