Skip to content

Commit 8ef1277

Browse files
committed
Do fallback redirect at router level
1 parent 2e90b23 commit 8ef1277

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

frontend/src/routes/_account.index.tsx

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ import AddEmailForm from "../components/UserProfile/AddEmailForm";
2727
import UserEmailList, {
2828
query as userEmailListQuery,
2929
} from "../components/UserProfile/UserEmailList";
30-
import { graphql } from "../gql";
30+
import {
31+
CONFIG_FRAGMENT as PLAN_MANAGEMENT_CONFIG_FRAGMENT,
32+
query as planManagementQuery,
33+
} from "./_account.plan.index";
34+
35+
import { graphql, useFragment } from "../gql";
3136
import { graphqlRequest } from "../graphql";
3237

3338
const QUERY = graphql(/* GraphQL */ `
@@ -96,7 +101,7 @@ const actionSchema = v.variant("action", [
96101
export const Route = createFileRoute("/_account/")({
97102
validateSearch: actionSchema,
98103

99-
beforeLoad({ search }) {
104+
async beforeLoad({ search, context }) {
100105
switch (search.action) {
101106
case "profile":
102107
case "org.matrix.profile":
@@ -129,10 +134,17 @@ export const Route = createFileRoute("/_account/")({
129134
to: "/reset-cross-signing",
130135
search: { deepLink: true },
131136
});
132-
case "org.matrix.plan_management":
137+
case "org.matrix.plan_management": {
138+
const { siteConfig } =
139+
await context.queryClient.ensureQueryData(planManagementQuery);
140+
const { planManagementIframeUri } = useFragment(
141+
PLAN_MANAGEMENT_CONFIG_FRAGMENT,
142+
siteConfig,
143+
);
133144
throw redirect({
134-
to: "/plan",
145+
to: planManagementIframeUri ? "/plan" : "/",
135146
});
147+
}
136148
}
137149
},
138150

frontend/src/routes/_account.plan.index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// Please see LICENSE in the repository root for full details.
55

66
import { queryOptions, useSuspenseQuery } from "@tanstack/react-query";
7-
import { createFileRoute, Navigate } from "@tanstack/react-router";
7+
import { Navigate, createFileRoute } from "@tanstack/react-router";
88
import { useCallback, useEffect, useRef, useState } from "react";
99
import { graphql, useFragment } from "../gql";
1010
import { graphqlRequest } from "../graphql";
@@ -23,7 +23,7 @@ const QUERY = graphql(/* GraphQL */ `
2323
}
2424
`);
2525

26-
const query = queryOptions({
26+
export const query = queryOptions({
2727
queryKey: ["siteConfig"],
2828
queryFn: ({ signal }) => graphqlRequest({ query: QUERY, signal }),
2929
});

0 commit comments

Comments
 (0)