-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2e86f35
commit fbe1b31
Showing
2 changed files
with
68 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from "react"; | ||
import { useRoutes, Outlet } from "react-router"; | ||
import { Link } from "react-router-dom"; | ||
|
||
const RouteAsObj = () => { | ||
let element = useRoutes([ | ||
{ path: "/", element: <Route1 /> }, | ||
{ path: "route2", element: <Route2 /> }, | ||
{ | ||
path: "route3", | ||
element: <Route3 />, | ||
children: [ | ||
{ path: "child1", element: <Child1 /> }, | ||
{ path: "child2", element: <Child2 /> }, | ||
], | ||
}, | ||
{ path: "*", element: <NotFound /> }, | ||
]); | ||
|
||
return ( | ||
<div> | ||
<ul> | ||
<li> | ||
<Link to="">Route1</Link> | ||
</li> | ||
<li> | ||
<Link to="route2">Route2</Link> | ||
</li> | ||
<li> | ||
<Link to="route3">Route3</Link> | ||
</li> | ||
</ul> | ||
{element} | ||
</div> | ||
); | ||
}; | ||
|
||
const Route1 = () => <h1>Route1</h1>; | ||
const Route2 = () => <h1>Route2</h1>; | ||
const Route3 = () => { | ||
return ( | ||
<div> | ||
<h1>Route3</h1> | ||
<ul> | ||
<li> | ||
<Link to="child1">Child1</Link> | ||
</li> | ||
<li> | ||
<Link to="child2">Child2</Link> | ||
</li> | ||
</ul> | ||
<Outlet /> | ||
</div> | ||
); | ||
}; | ||
const Child1 = () => <h2>Child1</h2>; | ||
const Child2 = () => <h2>Child2</h2>; | ||
const NotFound = () => <h1>NotFound</h1>; | ||
|
||
export default RouteAsObj; |