Skip to content

Commit

Permalink
Comment internalRoute
Browse files Browse the repository at this point in the history
  • Loading branch information
dac09 committed Mar 3, 2023
1 parent e086fbd commit 5e37a27
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/router/src/router.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,54 +76,64 @@ const InternalRoute = ({
const routerState = useRouterState()
const activePageContext = useActivePageContext()

// @DElETE no need because this is handled by the Router component
if (notfound) {
// The "notfound" route is handled by <NotFoundChecker>
return null
}

// @REIMPLEMENT we can do this in validatePath which gets called in LocationAwareRouter
if (!path) {
throw new Error(`Route "${name}" needs to specify a path`)
}

// @DELETE as above
// Check for issues with the path.
validatePath(path)

// @DELETE no longer exists
const location = activePageContext.loadingState[path]?.location

if (!location) {
throw new Error(`No location for route "${name}"`)
}

// @DELETE params are handled in the active-route-loader
const { params: pathParams } = matchPath(path, location.pathname, {
paramTypes: routerState.paramTypes,
})

const searchParams = parseSearch(location.search)
const allParams: Record<string, string> = { ...searchParams, ...pathParams }

// @REIMPLEMENT
if (redirect) {
const newPath = replaceParams(redirect, allParams)
return <Redirect to={newPath} />
}

// @REIMPLEMENT: possibly a new validateRoute function needed in Router
if (!page || !name) {
throw new Error(
"A route that's not a redirect or notfound route needs to specify " +
'both a `page` and a `name`'
)
}

// @DELETE no longer have activepagecontext
const Page = activePageContext.loadingState[path]?.page || (() => null)

// There are two special props in React: `ref` and `key`. (See https://reactjs.org/warnings/special-props.html.)
// It's very possible that the URL has `ref` as a search param (e.g. https://redwoodjs.com/?ref=producthunt).
// Since we pass URL params to the page, we have to be careful not to pass `ref` or `key`, otherwise the page will break.
// (The page won't actually break if `key` is passed, but it feels unclean.)
// If users want to access them, they can use `useParams`.

// @REIMPLEMENT: possibly in active-route-loader, or before we pass params
// to ARL in the Router component
delete allParams['ref']
delete allParams['key']

// Level 3/3 (InternalRoute)
// @DELETE
return <Page {...allParams} />
}

Expand Down

0 comments on commit 5e37a27

Please sign in to comment.