-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: [9] loading 파일에 대한 처리 추가
- Loading branch information
Showing
10 changed files
with
139 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { RouteObject } from 'react-router-dom'; | ||
import { RouteNode } from '../types'; | ||
import { wrapWithSuspense } from './suspens-wrapper'; | ||
import React from 'react'; | ||
|
||
/** | ||
* Creates a route object 함수 | ||
* @param node - RouteNode | ||
* @param path - route의 path | ||
* @returns RouteObject | ||
*/ | ||
export function createRouteObject(node: RouteNode, path?: string): RouteObject { | ||
const route: RouteObject = {}; | ||
|
||
const loadingComponent = node.loadingElement | ||
? React.createElement(node.loadingElement) | ||
: undefined; | ||
|
||
if (path) { | ||
route.path = path; | ||
} | ||
|
||
/** layout 처리 */ | ||
if (node.layoutElement) { | ||
route.element = wrapWithSuspense(node.layoutElement, loadingComponent); | ||
} | ||
|
||
/** error 처리 */ | ||
if (node.errorElement) { | ||
route.errorElement = wrapWithSuspense(node.errorElement, loadingComponent); | ||
} | ||
|
||
/** page 처리 */ | ||
if (node.pageElement) { | ||
const pageElement = wrapWithSuspense(node.pageElement, loadingComponent); | ||
|
||
if (node.layoutElement) { | ||
route.children = [ | ||
{ | ||
index: true, | ||
element: pageElement, | ||
errorElement: route.errorElement, | ||
}, | ||
]; | ||
} else { | ||
route.element = pageElement; | ||
} | ||
} | ||
|
||
return route; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.