-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Router: Fix Switch inside a SubRouteIndexRoute to allow a Stack in a …
…Stack initial page
- Loading branch information
Showing
6 changed files
with
200 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@comet/admin": patch | ||
--- | ||
|
||
Router: Fix Switch inside a SubRouteIndexRoute to allow a Stack in a Stack initial page |
69 changes: 69 additions & 0 deletions
69
packages/admin/admin-stories/src/admin/router/SubRouteNestedIndex.tsx
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,69 @@ | ||
import { SubRouteIndexRoute, useSubRoutePrefix } from "@comet/admin"; | ||
import { storiesOf } from "@storybook/react"; | ||
import * as React from "react"; | ||
import { Redirect, Route, Switch, useLocation } from "react-router"; | ||
import { Link } from "react-router-dom"; | ||
|
||
import { storyRouterDecorator } from "../../story-router.decorator"; | ||
|
||
function Cmp1() { | ||
const urlPrefix = useSubRoutePrefix(); | ||
return ( | ||
<div> | ||
<Switch> | ||
<Route path={`${urlPrefix}/sub`}> | ||
<p>Cmp1-Sub</p> | ||
</Route> | ||
<SubRouteIndexRoute> | ||
<p>Cmp1-Index</p> | ||
<Link to={`${urlPrefix}/sub`}>to-cmp1-sub</Link> | ||
</SubRouteIndexRoute> | ||
</Switch> | ||
</div> | ||
); | ||
} | ||
|
||
function Story() { | ||
return ( | ||
<div> | ||
<Switch> | ||
<SubRouteIndexRoute> | ||
<Cmp1 /> | ||
</SubRouteIndexRoute> | ||
<Route path="/sub">Sub</Route> | ||
</Switch> | ||
</div> | ||
); | ||
} | ||
|
||
function Path() { | ||
const location = useLocation(); | ||
const [, rerender] = React.useState(0); | ||
React.useEffect(() => { | ||
const timer = setTimeout(() => { | ||
rerender(new Date().getTime()); | ||
}, 1000); | ||
return () => clearTimeout(timer); | ||
}, []); | ||
return <div>{location.pathname}</div>; | ||
} | ||
|
||
function App() { | ||
return ( | ||
<> | ||
<Path /> | ||
<Switch> | ||
<Route exact path="/"> | ||
<Redirect to="/foo" /> | ||
</Route> | ||
<Route path="/foo"> | ||
<Story /> | ||
</Route> | ||
</Switch> | ||
</> | ||
); | ||
} | ||
|
||
storiesOf("@comet/admin/router", module) | ||
.addDecorator(storyRouterDecorator()) | ||
.add("Subroute nested index", () => <App />); |
67 changes: 67 additions & 0 deletions
67
packages/admin/admin-stories/src/admin/stack/StackNestedOnInitialPage.tsx
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,67 @@ | ||
import { Stack, StackBreadcrumbs, StackLink, StackPage, StackSwitch } from "@comet/admin"; | ||
import { storiesOf } from "@storybook/react"; | ||
import * as React from "react"; | ||
import { Redirect, Route, Switch, useLocation } from "react-router"; | ||
|
||
import { storyRouterDecorator } from "../../story-router.decorator"; | ||
|
||
function Path() { | ||
const location = useLocation(); | ||
const [, rerender] = React.useState(0); | ||
React.useEffect(() => { | ||
const timer = setTimeout(() => { | ||
rerender(new Date().getTime()); | ||
}, 1000); | ||
return () => clearTimeout(timer); | ||
}, []); | ||
return <div>{location.pathname}</div>; | ||
} | ||
function Page2() { | ||
return ( | ||
<Stack topLevelTitle="Stack Nested"> | ||
<StackBreadcrumbs /> | ||
<StackSwitch> | ||
<StackPage name="page1"> | ||
<StackLink payload="test" pageName="page2-2"> | ||
activate page2-2 | ||
</StackLink> | ||
</StackPage> | ||
<StackPage name="page2-2">page2</StackPage> | ||
</StackSwitch> | ||
</Stack> | ||
); | ||
} | ||
|
||
function Story() { | ||
return ( | ||
<> | ||
<Path /> | ||
<Stack topLevelTitle="Stack"> | ||
<StackBreadcrumbs /> | ||
<StackSwitch> | ||
<StackPage name="page1"> | ||
<Page2 /> | ||
</StackPage> | ||
<StackPage name="page2">page2</StackPage> | ||
</StackSwitch> | ||
</Stack> | ||
</> | ||
); | ||
} | ||
|
||
function App() { | ||
return ( | ||
<Switch> | ||
<Route exact path="/"> | ||
<Redirect to="/foo" /> | ||
</Route> | ||
<Route path="/foo"> | ||
<Story /> | ||
</Route> | ||
</Switch> | ||
); | ||
} | ||
|
||
storiesOf("@comet/admin/stack", module) | ||
.addDecorator(storyRouterDecorator()) | ||
.add("Stack Nested On Initial Page", () => <App />); |
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