mirror of
https://github.com/DefectingCat/DefectingCat.github.io
synced 2025-07-16 01:01:38 +00:00
* add ahooks library * add useAppDispatch and useAppSelector hooks * move out router event handle from useEffect * fix router events off
29 lines
665 B
TypeScript
29 lines
665 B
TypeScript
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
|
|
|
export interface RouterState {
|
|
fromPath: string;
|
|
}
|
|
|
|
const initialState: RouterState = {
|
|
// Record the from path when into the post page.
|
|
fromPath: '',
|
|
};
|
|
|
|
export const routerSlice = createSlice({
|
|
name: 'router',
|
|
initialState,
|
|
reducers: {
|
|
setFromPath: (state, action: PayloadAction<string>) => {
|
|
state.fromPath = action.payload;
|
|
},
|
|
cleanFromPath: (state) => {
|
|
state.fromPath = '';
|
|
},
|
|
},
|
|
});
|
|
|
|
// Action creators are generated for each case reducer function
|
|
export const { setFromPath, cleanFromPath } = routerSlice.actions;
|
|
|
|
export default routerSlice.reducer;
|