-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement router transitions #358
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
5325dbc
Implement router transitions
kpyszkowski 679876d
Merge branch 'main' into router-transitions
kpyszkowski 48cb5cd
Merge branch 'landing-page' into router-transitions
kpyszkowski d34c26b
Merge branch 'landing-page' into router-transitions
kpyszkowski adde7d5
Merge branch 'landing-page' into router-transitions
kpyszkowski eb37fa9
Move `GlobalStyles` one level higher in tree
kpyszkowski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,45 @@ | ||
import React, { useState } from "react" | ||
import { AnimatePresence, motion, Variants } from "framer-motion" | ||
import { useLocation, useOutlet } from "react-router-dom" | ||
import Header from "../Header" | ||
import DocsDrawer from "../DocsDrawer" | ||
import Sidebar from "../Sidebar" | ||
|
||
const wrapperVariants: Variants = { | ||
in: { opacity: 0, y: 48 }, | ||
out: { opacity: 0, y: -48 }, | ||
visible: { opacity: 1, y: 0 }, | ||
} | ||
|
||
// This tricky component makes Outlet persistent so React and Framer Motion can | ||
// distinguish wheather it should be rerendered between routes. | ||
// Ref: https://github.com/remix-run/react-router/discussions/8008#discussioncomment-1280897 | ||
function PersistentOutlet() { | ||
const [outlet] = useState(useOutlet()) | ||
ioay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return outlet | ||
} | ||
|
||
function Layout() { | ||
const location = useLocation() | ||
return ( | ||
<> | ||
<Header /> | ||
<AnimatePresence mode="popLayout"> | ||
<motion.main | ||
key={location.pathname} | ||
variants={wrapperVariants} | ||
transition={{ type: "spring", damping: 12, stiffness: 120 }} | ||
initial="in" | ||
animate="visible" | ||
exit="out" | ||
> | ||
<PersistentOutlet /> | ||
</motion.main> | ||
</AnimatePresence> | ||
<Sidebar /> | ||
<DocsDrawer /> | ||
</> | ||
) | ||
} | ||
|
||
export default Layout |
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 |
---|---|---|
@@ -1,22 +1,24 @@ | ||
import React from "react" | ||
import { createBrowserRouter } from "react-router-dom" | ||
import { BrowserRouter, Route, Routes } from "react-router-dom" | ||
import LandingPage from "#/pages/LandingPage" | ||
import OverviewPage from "#/pages/OverviewPage" | ||
import ActivityPage from "#/pages/ActivityPage" | ||
import Layout from "#/components/shared/Layout" | ||
import { routerPath } from "./path" | ||
|
||
export const router = createBrowserRouter([ | ||
{ | ||
path: routerPath.home, | ||
element: <LandingPage />, | ||
index: true, | ||
}, | ||
{ | ||
path: routerPath.overview, | ||
element: <OverviewPage />, | ||
}, | ||
{ | ||
path: `${routerPath.activity}/:activityId`, | ||
element: <ActivityPage />, | ||
}, | ||
]) | ||
export function Router() { | ||
return ( | ||
<BrowserRouter> | ||
<Routes> | ||
<Route path="/" element={<Layout />}> | ||
<Route index path={routerPath.home} element={<LandingPage />} /> | ||
<Route path={routerPath.overview} element={<OverviewPage />} /> | ||
<Route | ||
path={`${routerPath.activity}/:activityId`} | ||
element={<ActivityPage />} | ||
/> | ||
</Route> | ||
</Routes> | ||
</BrowserRouter> | ||
) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case when DApp returns only the
Router
component maybe we should consider moving this logic to the parent and then deleting this file simplifying the structure. What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case I'd opt for slightly different solution - to leave routing separated as is - routing is kind of hermetic area with it's "natural" namespace and it's good to have it separated in case the application scales and the need of new routes might occur.
My suggestion is to remove the
useInitApp
hook. Now whenDApp
component has such a simple structure this hook is only a redundant wrapper to click through when inspecting the code.What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd rather leave
useInitApp
as it is. I'm considering whether DAppProviders should returnGlobalStyles
(it's not a provider), so maybe we should move it toDApp
component to be semantically correct.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ref commit: eb37fa9