0
Fork 0
mirror of https://github.com/TanStack/router.git synced 2026-11-16 19:38:07 +00:00
router/docs/framework/react/api/router/createLazyFileRouteFunction.md
Sean Cassiere ab02f3ebd3
docs: moving reference content out of the class files (#1633)
* RouterType

* RouteApiType

* RouteType

* ParsedLocation linking

* linking RouterType, RouteType, and RouteApiType

* reduce SearchParamOptionsType and PathParamOptionsType into ToOptionsType

* useLinkProps

* forgot to remove that

* more
2024-05-19 14:52:44 +12:00

1.6 KiB

id title
createLazyFileRouteFunction createLazyFileRoute function

The createLazyFileRoute function is used for creating a partial file-based route route instance that is lazily loaded when matched. This route instance can only be used to configure the non-critical properties of the route, such as component, pendingComponent, errorComponent, and the notFoundComponent.

createLazyFileRoute options

The createLazyFileRoute function accepts a single argument of type string that represents the path of the file that the route will be generated from.

path

  • Type: string
  • Required, but automatically inserted and updated by the tsr generate and tsr watch commands
  • The full path of the file that the route will be generated from.

createLazyFileRoute returns

A new function that accepts a single argument of partial of the type RouteOptions that will be used to configure the file Route instance.

  • Type:
Pick<
  RouteOptions,
  'component' | 'pendingComponent' | 'errorComponent' | 'notFoundComponent'
>

⚠️ Note: For tsr generate and tsr watch to work properly, the file route instance must be exported from the file using the Route identifier.

Examples

import { createLazyFileRoute } from '@tanstack/react-router'

export const Route = createLazyFileRoute('/')({
  component: IndexComponent,
})

function IndexComponent() {
  const data = Route.useLoaderData()
  return <div>{data}</div>
}