mirror of
https://github.com/usememos/memos.git
synced 2024-12-19 09:02:49 +03:00
fix: route confusion entering from non-home page (#460)
Co-authored-by: boojack <stevenlgtm@gmail.com>
This commit is contained in:
parent
407d1cdcaa
commit
a90acdabb3
@ -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) {
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user