action.js:
export const login = creds => {
console.log(`${url}/login`);
const requestOptions = {
method: "POST",
headers: {
Accept: "application/json",
"Content-Type": "application/json"
},
body: creds
};
return function(dispatch) {
dispatch({ type: LOGIN_REQUEST });
function timer() {
return fetch(`${url}/login`, requestOptions).then(response => {
if (!response.ok) {
console.log(response);
return response.json().then(json => {
var error = new Error(json.message);
error.response = response;
throw error;
});
} else {
console.log("3");
return response.json();
}
}).then(user => {
if (user.message === "ok") {
localStorage.setItem("token", user.token);
dispatch({ type: LOGIN_SUCCESS, …Run Code Online (Sandbox Code Playgroud) 当我从 /home 导航到 /dashboard 时,路由器工作正常,但是当我从 /home 导航到 /profile:id 时,路由器将我导航到也工作正常的配置文件页面,但是当我刷新它时,它会变成空白页面并且没有给我任何 404 或重定向回主页,我正在使用
react-router: "^4.2.0",
react-router-dom: "^4.2.2",
react-router-redux: "5.0.0-alpha.6",
那么,如何摆脱空白页面,如果 url 位于 /profile/5,然后在刷新页面上导航回主页或任何适当的内容,请帮忙?
索引.js
ReactDOM.render(
<Provider store={store}>
<ConnectedRouter history={history}>
<Switch>
<Route path="/" component={App} />
<Route component={Page404} />
</Switch>
</ConnectedRouter>
</Provider>,
document.getElementById('app-site')
);
Run Code Online (Sandbox Code Playgroud)
应用程序.js
<Switch>
<Route path={`/login`} component={LoginMember} />
<Route path={`/registermember`} component={SignUp} />
<Authentication component={AuthenticateRoute} />
<Route component={Page404} />
</Switch>
const AuthenticateRoute = ({ match }) => (
<Switch>
<Authentication path={`${match.url}`} component={MainApp} />
<Route component={Page404} />
</Switch>
);
Run Code Online (Sandbox Code Playgroud)
主应用程序
<Switch>
<Route path={`/home`} component={Home} …Run Code Online (Sandbox Code Playgroud) 我想根据发出的请求单独显示每个请求的加载程序,假设在仪表板中我有多个小部件,并且它们都有不同的 api 调用,我想为每个发出的请求显示不同的加载程序,
一种方法是为每个发出的请求添加isLoading标志,我认为随着应用程序的增长,这不是一个好的解决方案,并且我正在寻找可以处理来自一个标志的多个请求的解决方案
那么我应该如何根据每个请求制作动态的单独加载器
下面是我的减速器和动作
减速器
export const intialstate = {
isAuth: false,
isLoading: false,
btnDisable: false
};
export default function(state = intialstate, action) {
switch (action.type) {
case API_REQUEST:
return {
...state,
isLoading: true,
};
case API_SUCCESS:
return {
...state,
isLoading: false,
isError: null
};
case API_FAILURE:
return {
...state,
isError: action.payload,
isLoading: false,
};
// no default
}
return state;
}
Run Code Online (Sandbox Code Playgroud)
动作.js
export const AnyAPIRequest = () => {
return (dispatch) => {
dispatch({
type: …Run Code Online (Sandbox Code Playgroud) 我想从列表中完全删除一个项目,下面是列表
var list = [{id: 1, match_number: 1, name: "match1"},
{id: 2, match_number: 2, name: "match2"},
{id: 3, match_number: 3, name: "match3"},
{id: 4, match_number: 4, name: "match4"},
{id: 5, match_number: 5, name: "match5"}]
Run Code Online (Sandbox Code Playgroud)
我想match_number从列表中完全删除,并希望实现像
var list = [{id: 1, name: "match1"},
{id: 2, name: "match2"},
{id: 3, name: "match3"},
{id: 4, name: "match4"},
{id: 5, name: "match5"}]
Run Code Online (Sandbox Code Playgroud)
下面是我获得单个项目结果的代码,但是我有一个数组,其中键给出了像['match_number','id'].在此基础上我想从主列表中删除项目.
我怎么解决这个问题?
//code for single item
var listitem = list.map((i) => {
const {match_number,...item} = i;
return item; …Run Code Online (Sandbox Code Playgroud) javascript ×3
react-redux ×3
reactjs ×3
react-router ×2
redux ×2
arraylist ×1
arrays ×1
jquery ×1
redux-thunk ×1
router ×1