diff --git a/.changeset/fix-hash-router-account-switcher-path.md b/.changeset/fix-hash-router-account-switcher-path.md
new file mode 100644
index 000000000..17f718f27
--- /dev/null
+++ b/.changeset/fix-hash-router-account-switcher-path.md
@@ -0,0 +1,5 @@
+---
+default: patch
+---
+
+Fix account switcher's add account button redirecting to the wrong path when hashRouter is enabled
diff --git a/src/app/pages/auth/AuthLayout.tsx b/src/app/pages/auth/AuthLayout.tsx
index 9a4cd8b85..3d725992e 100644
--- a/src/app/pages/auth/AuthLayout.tsx
+++ b/src/app/pages/auth/AuthLayout.tsx
@@ -30,6 +30,7 @@ import type { SpecVersions } from '../../cs-api';
import { ServerPicker } from './ServerPicker';
import * as css from './styles.css';
import { AuthFooter } from './AuthFooter';
+import { usePathWithOrigin } from '$hooks/usePathWithOrigin';
const currentAuthPath = (pathname: string): string => {
if (matchPath(LOGIN_PATH, pathname)) {
@@ -117,6 +118,8 @@ export function AuthLayout() {
const clientConfig = useClientConfig();
+ const homeUrl = usePathWithOrigin(getHomePath());
+
const defaultServer = clientDefaultServer(clientConfig);
const decodedServer = urlEncodedServer && decodeURIComponent(urlEncodedServer);
let server: string = decodedServer ?? defaultServer;
@@ -208,11 +211,7 @@ export function AuthLayout() {
Adding account
- window.location.assign(getHomePath())}
- >
+ window.location.assign(homeUrl)}>
Cancel
diff --git a/src/app/pages/client/sidebar/AccountSwitcherTab.tsx b/src/app/pages/client/sidebar/AccountSwitcherTab.tsx
index e46d427fe..bb1ff8b29 100644
--- a/src/app/pages/client/sidebar/AccountSwitcherTab.tsx
+++ b/src/app/pages/client/sidebar/AccountSwitcherTab.tsx
@@ -47,6 +47,7 @@ import { UnreadBadge, UnreadBadgeCenter } from '$components/unread-badge';
import { Check, chipIcon, GearSix, menuIcon, Plus } from '$components/icons/phosphor';
import { useSetting } from '$state/hooks/settings';
import { settingsAtom } from '$state/settings';
+import { usePathWithOrigin } from '$hooks/usePathWithOrigin';
const log = createLogger('AccountSwitcherTab');
@@ -179,6 +180,8 @@ export function AccountSwitcherTab({ isBottom }: { isBottom?: boolean }) {
const { disableAccountSwitcher } = useClientConfig();
+ const loginUrl = usePathWithOrigin(getLoginPath());
+
const handleToggle: MouseEventHandler = (evt) => {
if (disableAccountSwitcher) {
openSettings();
@@ -245,7 +248,7 @@ export function AccountSwitcherTab({ isBottom }: { isBottom?: boolean }) {
);
const handleAddAccount = () => {
- const url = withSearchParam(getLoginPath(), { addAccount: '1' });
+ const url = withSearchParam(loginUrl, { addAccount: '1' });
setMenuAnchor(undefined);
stopClient(mx);
setTimeout(() => window.location.assign(url), 100);