Skip to content

Commit

Permalink
fix(projects): update redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
mufeng889 committed Aug 26, 2024
1 parent f63e71e commit dc18c38
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/router/elegant/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ export const generatedRoutes: GeneratedRoute[] = [
{
name: 'login',
path: '/login',
component: 'layout.blank',
redirectTo: 'pwd-login',
component: 'layout.undefined',
redirect: 'pwd-login',
layout: 'blank',
meta: {
title: 'login',
Expand Down
14 changes: 7 additions & 7 deletions src/router/elegant/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import type { LazyRouteFunction, RouteObject,IndexRouteObject } from "react-rout
import type { FunctionComponent } from "react";
import type { ElegantConstRoute } from '@ohh-889/react-auto-route';
import type { RouteMap, RouteKey, RoutePath } from '@elegant-router/types';
import { redirect } from 'react-router-dom'
import ErrorBoundary from '../../../ErrorBoundary.tsx'
import { redirect as redirectTo } from 'react-router-dom'
import ErrorBoundary from "../../../ErrorBoundary.tsx"


type CustomRouteObject = Omit<RouteObject, 'Component'|'index'> & {
Expand Down Expand Up @@ -94,7 +94,7 @@ export function transformElegantRouteToReactRoute(
}


const { name,props, path,meta, component, children,redirectTo,layout,loader, ...rest } = route;
const { name,props, path,meta, component, children,redirect,layout,loader, ...rest } = route;

const reactRoute = {id:name, path,handle: {
...meta
Expand Down Expand Up @@ -172,15 +172,15 @@ export function transformElegantRouteToReactRoute(

if (children?.length) {
reactRoute.children = children.flatMap(child => transformElegantRouteToReactRoute(child, layouts, views));
const defaultRedirectPath = redirectTo || getRedirectPath(path as string, children[0].path as string);
const defaultRedirectPath = redirect || getRedirectPath(path as string, children[0].path as string);

reactRoute.children.unshift({
index: true,
loader: () => redirect(defaultRedirectPath),
loader: () => redirectTo(defaultRedirectPath),
...rest
});
}else if (redirectTo) {
reactRoute.loader=()=>redirect(redirectTo)
}else if (redirect) {
reactRoute.loader=()=>redirectTo(redirect)
}

if (loader) {
Expand Down
2 changes: 1 addition & 1 deletion src/router/routes/builtin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getRoutePath } from '../elegant/transform';
export const ROOT_ROUTE: CustomRoute = {
name: 'root',
path: '/',
redirectTo: getRoutePath(import.meta.env.VITE_ROUTE_HOME) || '/home',
redirect: getRoutePath(import.meta.env.VITE_ROUTE_HOME) || '/home',
meta: {
title: 'root',
constant: true
Expand Down

0 comments on commit dc18c38

Please sign in to comment.