fix: route confusion entering from non-home page (#460)

Co-authored-by: boojack <stevenlgtm@gmail.com>
This commit is contained in:
Stephen Zhou 2022-11-13 19:40:16 +08:00 committed by GitHub
parent 407d1cdcaa
commit a90acdabb3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View File

@ -1,8 +1,11 @@
import { stringify } from "qs";
import store from "../store";
import { setQuery, setPathname, Query, updateStateWithLocation } from "../store/modules/location";
import { setQuery, setPathname, Query, updateStateWithLocation, updatePathnameStateWithLocation } from "../store/modules/location";
const updateLocationUrl = (method: "replace" | "push" = "replace") => {
// avoid pathname confusion when entering from non-home page
store.dispatch(updatePathnameStateWithLocation());
const { query, pathname, hash } = store.getState().location;
let queryString = stringify(query);
if (queryString) {

View File

@ -64,6 +64,13 @@ const locationSlice = createSlice({
updateStateWithLocation: () => {
return getStateFromLocation();
},
updatePathnameStateWithLocation: (state) => {
const { pathname } = window.location;
return {
...state,
pathname: getValidPathname(pathname),
};
},
setPathname: (state, action: PayloadAction<string>) => {
if (state.pathname === action.payload) {
return state;
@ -90,6 +97,6 @@ const locationSlice = createSlice({
},
});
export const { setPathname, setQuery, updateStateWithLocation } = locationSlice.actions;
export const { setPathname, setQuery, updateStateWithLocation, updatePathnameStateWithLocation } = locationSlice.actions;
export default locationSlice.reducer;