Skip to content

createRouteView

Creates an eager RouteView that binds an effector/router route or nested router to a Solid component.

API

ts
function createRouteView<T extends object | void = void>(
  props: CreateRouteViewProps<T>,
): RouteView;
PropertyTypeDescription
routeRoute<T> | RouterUnit that controls whether the view opens
viewComponentComponent rendered for the opened unit
layoutComponent<{ children: JSX.Element }>Optional wrapper component
childrenRouteView[]Optional direct child views for Outlet

Usage

tsx
import { createRouteView } from '@effector/router-solid';

const ProfileScreen = createRouteView({
  route: profileRoute,
  view: () => <h1>Profile</h1>,
  layout: MainLayout,
});

Route parameters remain available through Effector units. useUnit returns a Solid accessor:

tsx
import { useUnit } from 'effector-solid';

const UserScreen = createRouteView({
  route: userRoute,
  view: () => {
    const params = useUnit(userRoute.$params);
    return <h1>User {params().id}</h1>;
  },
});

Use children with Outlet for nested views. A Router target is active while its $activeRoutes is non-empty.

Released under the MIT License.