Skip to content

Commit

Permalink
Warn only when route element is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
mjackson committed Oct 23, 2021
1 parent 71683a0 commit 66153dc
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/react-router/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ export function useHref(to: To): string {
: joinPaths([basename, pathname]);
}

return navigator.createHref({ hash, pathname: joinedPathname, search });
return navigator.createHref({ pathname: joinedPathname, search, hash });
}

/**
Expand Down Expand Up @@ -634,7 +634,8 @@ export function useRoutes(
);

warning(
matches == null || matches[matches.length - 1].route.element != null,
matches == null ||
matches[matches.length - 1].route.element !== undefined,
`Matched leaf route at location "${location.pathname}${location.search}${location.hash}" does not have an element. ` +
`This means it will render an <Outlet /> with a null value by default resulting in an "empty" page.`
);
Expand Down Expand Up @@ -977,7 +978,9 @@ function _renderMatches(
return matches.reduceRight((outlet, match, index) => {
return (
<RouteContext.Provider
children={match.route.element || <Outlet />}
children={
match.route.element !== undefined ? match.route.element : <Outlet />
}
value={{
outlet,
matches: parentMatches.concat(matches.slice(0, index + 1))
Expand Down

0 comments on commit 66153dc

Please sign in to comment.