better way
This commit is contained in:
parent
6f77a07cda
commit
d380f259b1
|
|
@ -1,18 +1,13 @@
|
||||||
import { redirect } from "@tanstack/react-router";
|
import { redirect } from "@tanstack/react-router";
|
||||||
import { useParams } from "@tanstack/react-router";
|
|
||||||
import { requireChains } from "@/entities/chain/lib";
|
import { requireChains } from "@/entities/chain/lib";
|
||||||
import { createFileRoute } from "@tanstack/react-router";
|
import { createFileRoute } from "@tanstack/react-router";
|
||||||
import { useNavigate } from "@tanstack/react-router";
|
|
||||||
|
|
||||||
import { useChainState } from "@/entities/chain/model";
|
import { useChainState } from "@/entities/chain/model";
|
||||||
import { Typography } from "@mui/material";
|
import { Typography } from "@mui/material";
|
||||||
import { ChainButtons } from "@/widgets/chain-buttons";
|
import { ChainButtons } from "@/widgets/chain-buttons";
|
||||||
|
|
||||||
function ChainPage() {
|
function ChainPage() {
|
||||||
const navigate = useNavigate({ from: "/$namespace/$chainId" });
|
const { chain } = Route.useLoaderData();
|
||||||
const { chainId } = useParams({ from: "/$namespace/$chainId" });
|
|
||||||
const chain = useChainState((state) => state.getChain(chainId));
|
|
||||||
if (!chain) return navigate({ to: "/$namespace" });
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
@ -43,5 +38,7 @@ export const Route = createFileRoute("/$namespace/$chainId")({
|
||||||
|
|
||||||
const selectedChain = chainState.getChain(params.chainId);
|
const selectedChain = chainState.getChain(params.chainId);
|
||||||
if (!selectedChain) throw redirect({ to: "/$namespace", params });
|
if (!selectedChain) throw redirect({ to: "/$namespace", params });
|
||||||
|
|
||||||
|
return { chain: selectedChain };
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user