react-redux无法刷新当前页面

时间:2019-03-09 15:50:35

标签: reactjs redux react-redux

在我的应用程序中,我使用redux进行导航。就像这样:

<div 
    onClick={()=>this.props.action.EntryAction("search", {})}
>
    <span>Search</span>
</div> 

动作:

export function EntryAction(entry, dataSource) { 
    return function action(dispatch){
        dispatch({type:entry, dataSource:dataSource})
    }
}

Reducer:

function EntryReducer(state=initValue, action){

    return {...state, entry:action.type};
}
const initValue = {
    entry:"search"
}

应用

class App extends Component {
    ...
    handOutEntry(){
        switch(this.props.entry.entry){
            case "search":
                return <Entry.Search />
            case "home":
                return <Entry.Home />
            default:
                return <Entry.Search />
        }
    }
    render(){
        let entry = this.handOutEntry()
        return(
            <div>
                {entry}
            </div>
        )
    }
}

我可以轻松地将页面从“搜索”更改为“主页”,但是我无法刷新当前页面。例如,当前页面为“搜索”,如果单击搜索导航,则页面完全不会更改。刷新当前页面。

0 个答案:

没有答案
相关问题