Skip to content

Commit

Permalink
Set up strategy page redirect for empty id
Browse files Browse the repository at this point in the history
  • Loading branch information
tiagofilipenunes committed Oct 2, 2024
1 parent 6bb9074 commit e224363
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
8 changes: 6 additions & 2 deletions src/libs/routing/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,18 @@ import {
editBudgetRecurring,
} from './strategyEdit';
import tradePage from 'libs/routing/routes/trade';
import { strategyPage } from 'libs/routing/routes/strategy';
import {
strategyPage,
strategyPageRedirect,
strategyPageRoot,
} from 'libs/routing/routes/strategy';

export const routeTree = rootRoute.addChildren([
termPage,
privacyPage,
debugPage,
tradePage,
strategyPage,
strategyPageRoot.addChildren([strategyPage, strategyPageRedirect]),
oldCreateStrategies,
editStrategyLayout.addChildren([
editPricesDisposable,
Expand Down
20 changes: 17 additions & 3 deletions src/libs/routing/routes/strategy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { StrategyPage } from 'pages/strategy';
import { rootRoute } from './root';
import { createRoute } from '@tanstack/react-router';
import { createRoute, redirect } from '@tanstack/react-router';
import { InferSearch, searchValidator, validNumber } from '../utils';
import { activityValidators } from 'components/activity/utils';
import { defaultEnd, defaultStart } from 'components/strategies/common/utils';
Expand All @@ -15,9 +15,23 @@ const schema = {

export type StrategyPageSearch = InferSearch<typeof schema>;

export const strategyPage = createRoute({
export const strategyPageRoot = createRoute({
getParentRoute: () => rootRoute,
path: 'strategy/$id',
path: 'strategy',
});

export const strategyPage = createRoute({
getParentRoute: () => strategyPageRoot,
path: '$id',
component: StrategyPage,
validateSearch: searchValidator(schema),
});

export const strategyPageRedirect = createRoute({
getParentRoute: () => strategyPageRoot,
path: '/',
beforeLoad: ({ location }) => {
if (location.pathname === '/strategy' || location.pathname === '/strategy/')
redirect({ to: '/', throw: true, replace: true });
},
});

0 comments on commit e224363

Please sign in to comment.