Skip to content

Commit

Permalink
fix(flat-web): blocking browser fallback (#857)
Browse files Browse the repository at this point in the history
* fix(login): replace history instead of push

close #856

* correct comment
  • Loading branch information
hyrious authored Aug 11, 2021
1 parent 62027fd commit d833d18
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions web/flat-web/src/pages/HomePage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ import { observer } from "mobx-react-lite";
import { MainRoomMenu } from "./MainRoomMenu";
import { MainRoomListPanel } from "./MainRoomListPanel";
import { MainRoomHistoryPanel } from "./MainRoomHistoryPanel";
import { RouteNameType, usePushHistory } from "../../utils/routes";
import { RouteNameType, useReplaceHistory } from "../../utils/routes";
import { GlobalStoreContext, PageStoreContext } from "../../components/StoreProvider";
import { loginCheck } from "../../apiMiddleware/flatServer";
import { errorTips } from "../../components/Tips/ErrorTips";

export const HomePage = observer(function HomePage() {
const pushHistory = usePushHistory();
const replaceHistory = useReplaceHistory();
const globalStore = useContext(GlobalStoreContext);
const pageStore = useContext(PageStoreContext);
const [isLogin, setIsLogin] = useState(false);
Expand Down Expand Up @@ -51,7 +51,7 @@ export const HomePage = observer(function HomePage() {
if (isLoggedIn) {
setIsLogin(true);
} else {
pushHistory(RouteNameType.LoginPage);
replaceHistory(RouteNameType.LoginPage);
}
}
});
Expand Down
19 changes: 19 additions & 0 deletions web/flat-web/src/utils/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,22 @@ export function usePushHistory(): <T extends RouteNameType>(

return pushHistory;
}

/**
* Replace history with Flat route
*/
export function useReplaceHistory(): <T extends RouteNameType>(
name: T,
params?: RouteParams<T>,
) => void {
const history = useHistory();

const pushHistory = useCallback(
(name: RouteNameType, params: RouteParams<RouteNameType> = {}) => {
history.replace(generateRoutePath(name, params));
},
[history],
);

return pushHistory;
}

0 comments on commit d833d18

Please sign in to comment.