React Router API Reference
    Preparing search index...

    Variable createRoutesFromElementsConst

    createRoutesFromElements: (
        children: ReactNode,
        parentPath?: number[],
    ) => RouteObject[] = createRoutesFromChildren

    Create route objects from JSX elements instead of arrays of objects.

    Type declaration

      • (children: ReactNode, parentPath?: number[]): RouteObject[]
      • Creates a route config from a React "children" object, which is usually either a <Route> element or an array of them. Used internally by <Routes> to create a route config from its children.

        Parameters

        • children: ReactNode

          The React children to convert into a route config

        • parentPath: number[] = []

          The path of the parent route, used to generate unique IDs.

        Returns RouteObject[]

        An array of RouteObjects that can be used with a DataRouter

        data

    const routes = createRoutesFromElements(
    <>
    <Route index loader={step1Loader} Component={StepOne} />
    <Route path="step-2" loader={step2Loader} Component={StepTwo} />
    <Route path="step-3" loader={step3Loader} Component={StepThree} />
    </>
    );

    const router = createBrowserRouter(routes);

    function App() {
    return <RouterProvider router={router} />;
    }

    createRoutesFromElements

    data

    The React children to convert into a route config

    The path of the parent route, used to generate unique IDs. This is used for internal recursion and is not intended to be used by the application developer.

    An array of RouteObjects that can be used with a DataRouter