let breadcrumbItem = [];

 // 将数组中重复的数据去重
 function unip(arr) {
    var result = [];
    var obj = {};
    for(var i =0; i<arr.length; i++){
        if(!obj[arr[i].path]){
            result.push(arr[i]);
            obj[arr[i].path] = true;
        }
    }
    return result;
}

export default function headerRedux(state = breadcrumbItem, action) {
    if (action.type === 'breadcrumArr') {
        if (state.length >= 10) {
            // 判断当前state中是否包含传入进来的数据，如果不包含则删除第一个
            if (state.indexOf(action.value) === -1) {
                let arr = state.slice(1);
                return unip([...arr, action.value]);
            } else {// 如果包含则返回原数组
                return unip([...state])
            }
        } else {
            return unip([...state, action.value]);
        }
    } 
    else if (action.type === 'breadcrumDelete') {
        return state.filter(function(item){ return action.vaule !== item});
    }
    else if (action.type === 'breadcrumDeleteArr') {
        return [];
    }
    else {
        return state;
    }
}