redux-router pushState不是一个函数
redux-router pushState is not a function
从这个项目https://github.com/joshgeller/react-redux-jwt-auth-example#how-it-works,我有一个错误在
import { pushState } from 'redux-router';
...
checkAuth (isAuthenticated) {
if (!isAuthenticated) {
let redirectAfterLogin = this.props.location.pathname;
this.props.dispatch(pushState(null, `/signin?next=${redirectAfterLogin}`));
}
}
...
上面写着Uncaught TypeError: (0 , _reduxRouter.pushState) is not a function
。
我不按原样运行项目,我正在实现对我自己的项目的身份验证。我错过什么了吗?
将历史记录添加到Router (createHistory)中很重要。注意:如果你安装了当前的历史记录(v 4.3.0),它没有createHistory函数->请使用较低的(v. 3.*.)
存储:
import {combineReducers} from 'redux'
import {routerReducer} from 'react-router-redux'
import { createHistory } from 'history';
{...more imports}
const reducer = combineReducers({
...rootReducer,
routing: routerReducer
});
function configureStore(initialState) {
return createStore(
reducer,
initialState,
composeEnhancers(
applyMiddleware(
thunkMiddleware
),
reduxReactRouter({createHistory})
)
)
}
export const store = configureStore(
{}
);
渲染组件到DOM
import {store} from './store/store';
import {syncHistoryWithStore} from 'react-router-redux'
import { browserHistory } from 'react-router';
{...more imports}
const history = syncHistoryWithStore(browserHistory, store);
ReactDOM.render(
<Provider store={store}>
<Router history={history}>
{...}
</Router>
</Provider>,
document.getElementById('root')
)
现在可以使用pushState-Function
import { pushState } from 'redux-router';
export function logoutAndRedirect() {
return (dispatch, state) => {
dispatch(logout());
dispatch(pushState(null, '/login'));
}
}
我希望我没有忘记任何东西。->添加您的历史模块到存储
相关文章:
- 我可以在json对象中添加一个函数吗
- 如何在JQuery函数中定义一个值,然后调用另一个函数并使用该值
- 是否可以将一个函数输入连接到另一个函数调用的文本
- 在另一个函数中使用变量this
- 在另一个函数成功结束后调用该函数
- mongoose.connect undefined不是一个函数
- 监听器必须是一个函数
- 使用JS函数来使用另一个函数的语法?node.js
- 如何取消object.prototypes javascript的一个函数
- 从Chrome扩展名中的popup.html文件在background.js文件中运行一个函数
- 嵌套到另一个函数中的Fancybox函数;不起作用
- 如何在javascript中使用不止一个函数
- jQuery-在页面加载时执行一个函数
- jquery UI draggable:UI.children不是一个函数
- jQuery Mobile Undefined不是一个函数
- 如何在php中创建一个函数,该函数与文本区域一起工作,通过输入类似[color:red]的内容来打印具有等效颜色的文本
- javascript函数将数据添加到屏幕,但随后被另一个函数覆盖
- JS异常:animate不是一个函数
- 如何将一个函数附加到一个不存在的元素上
- JavaScript/jQuery-添加添加和删除类与下一个函数之间的延迟