-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Bumps react-router-dom
to v6
#2256
Conversation
Signed-off-by: Mihovil Ilakovac <[email protected]>
Signed-off-by: Mihovil Ilakovac <[email protected]>
@@ -14,7 +14,7 @@ export function OAuthCallbackPage() { | |||
const { error, user } = useOAuthCallbackHandler(); | |||
|
|||
if (user !== undefined && user !== null) { | |||
return <Redirect to="{= onAuthSucceededRedirectTo =}" />; | |||
return <Navigate to="{= onAuthSucceededRedirectTo =}" replace />; |
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.
<Navigate />
replace <Redirect />
and the default behaviour changed, we need to add replace
explicitly.
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.
If you got links to the changelog that prescribes this, you can include it into these comments.
I'm not sure is it worth spending the time, but it would help me better judge the change's validity.
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.
https://reactrouter.com/en/main/upgrading/v5#use-usenavigate-instead-of-usehistory
If you prefer to use a declarative API for navigation (ala v5's Redirect component), v6 provides a Navigate component.
2f9f954
to
5ef793d
Compare
}]) | ||
|
||
|
||
export const router = <RouterProvider router={browserRouter} /> |
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.
From the docs:
You should only opt into the Component API for data routes via RouterProvider. Using this API on a inside will de-optimize React's ability to reuse the created element across renders.
Since we are using Component
and not element API, using the RouterProvider
is optimal.
eda1098
to
dce8f8c
Compare
1118cf3
to
389713f
Compare
389713f
to
8584aa4
Compare
dd970a1
to
1bfef24
Compare
@@ -61,7 +62,9 @@ export const Layout = ({ children }: { children: ReactNode }) => { | |||
<Navbar.Link href="#">Contact</Navbar.Link> | |||
</Navbar.Collapse> */} | |||
</Navbar> | |||
<div className="grid place-items-center mt-8">{children}</div> | |||
<div className="grid place-items-center mt-8"> | |||
<Outlet /> |
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.
Breaking change: children
-> <Outlet />
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.
Yes, children are often used as an emotional outlet for their parents, checks out.
|
||
import { FullPageWrapper } from './FullPageWrapper' | ||
|
||
export function DefaultRootErrorBoundary() { |
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.
We are using a default root error boundary to make it look nicer when rendering fails. In the future, we should allow customisation of the root error boundary: #2279
@@ -21,7 +21,7 @@ export type Search = | |||
|
|||
type RouteDefinitionsToRoutesObj<Routes extends RoutesDefinition> = { | |||
[K in keyof Routes]: { | |||
to: Routes[K]['to'] | |||
to: ExpandRouteOnOptionalStaticSegments<Routes[K]['to']> |
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.
This is a bit of Typescript type level programming magic. It converts string literals that have a route with optional static segments into a union of string literals of possible route variants.
ExpandRouteOnOptionalStaticSegments<'/my/:id/route?'>
will result in '/my/:id' | '/my/:id/route'
type.
6b17b06
to
c571ea7
Compare
Signed-off-by: Mihovil Ilakovac <[email protected]>
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.
Nice work!
I'm still looking at the types file, but more out of curiosity than necessity.
If we fix everything else, it can go as is.
Signed-off-by: Mihovil Ilakovac <[email protected]>
Signed-off-by: Mihovil Ilakovac <[email protected]>
waspc/src/Wasp/Util/WebRouterPath.hs
Outdated
else RequiredStaticSegment segmentValue | ||
|
||
isSegmentOptional :: String -> Bool | ||
isSegmentOptional = isSuffixOf "?" |
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.
This is definitely a candidate for a local where
definition.
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.
Good call, I agree 👍
Closes #2245
Left to do
Link
component.build
method on the routeuseHistory
is replaced withuseNavigate
)<Link />
component docsmatch.params
rootComponent
to use<Outlet />
instead ofchildren
Breaking changes
useHistory()
->useNavigate()
<Redirect />
-><Navigate />
<Outlet />
instead of rendering childrenprops.match.params
->useParams()