路由平台搭建知识点遗漏

中间件

import {createStore , applyMiddleware} from "redux";
import reducer from "./reducers/index.js";
import { createLogger } from 'redux-logger';
import thunk from "redux-thunk";

//任何对state的改变之前都会顺序执行中间件。
let store = createStore(reducer,applyMiddleware(createLogger(),thunk));

获取后面的路由地址

window.location.hash

"我爱你亲爱的祖国的人民币".substr(6,2)

祖国


split() 把字符串→数组, 从什么地方拆分, 就是参数

"我爱你亲爱的祖国的人民币".split("的");  

[“我爱你亲爱”,“祖国”,“人民币”]


主页合并的时候,reducer也会被合并,会自动将返回的reducer加上investReducer

const store = createStore(
  combineReducers({
  //下面有两个ruducer
    investReducer,
    routing: routerReducer
  }),applyMiddleware(createLogger(),thunk)
);
let initState ={
    "filter" : {
         "schools" : ["新东方" , "新西方" , "蓝翔" , "爱前端" , "爱苹果"]
    }
}
export default (state = initState , action) => {
    return state;
}
export default connect(
    (state)=>{
        console.log(state);
    }
    )(Invest);

结果如下:

{investReducer: {…}, routing: {…}}
{investReducer: {…}, routing: {…}}
investReducer:
filter: {schools: Array(5)}
routing: {locationBeforeTransitions: null}

所以,在接收reducer的时候

export default connect((state)=>{
    return {
    // 要 state.investReducer,再加接收的变量
        "filters" : state.investReducer.filters,
        "nowfilter" : state.investReducer.nowfilter,
    }
})(Invest);

猜你喜欢

转载自blog.csdn.net/qq_43137725/article/details/82525940

相关文章