1.1.8 • Published 1 year ago

mobx-react-router-simple v1.1.8

Weekly downloads
-
License
ISC
Repository
github
Last release
1 year ago

mobx-react-router

Example

const routes: ConfigRoute[] = [
  {
    path: "/a",
    component: () => <div>a</div>,
  },
  {
    path: "/b",
    component: () => <div>b</div>,
  },
  {
    path: "/c",
    component: (props) =>
    <>
      <div>c</div>
      <Outlet {...props}/> // child routes
    </>,
    children: [
      {
        path: "/c/:id", // dynamic path
        component: (props) =>  
        <>
          <div>cc</div>
          <Outlet {...props}/>
        </>,
      },
      {
        path: "/c/b",
        component: (props) => 
        <>
          <div>ccx</div>
          <Outlet {...props}/>
        </>,
        children: [
          {
            path: "/c/:a/bb",
            component: () => <div>cccc</div>,
          },
        ],
      },
    ],
  },
  {
    path: "/*", // default route
    component: () => <div>b</div>,
  },
];

<Router routes={routes}/>

Public Api

routerStore

currentRouteRouteStore
getSearchParamsRecord<string, unknown>
getParamsRecord<string, unknown>
getMetaRecord<string, unknown>
navigateNavigatePayload
export interface NavigatePayload {
  pathname: string;
  searchParams?: Record<string, string>;
  replace?: boolean;
  hash?: string;
}

Route

navigatestring
hoststring
hostnamestring
hrefstring
originstring
passwordstring
pathnamestring
portstring
protocolstring
searchstring
usernamestring
searchParamsRecord<string, unknown>
paramsRecord<string, unknown>
configRouteConfigRoute
interface ConfigRoute {
  path: string;
  meta?: Record<string, string>;
  beforeEnter?: (configRoute: ConfigRoute, previousRoute?: RouteStore) => Promise<void>;
  component: FC<RouteComponentProps>;
  children?: ConfigRoute[];
}

Components

NavLink

type NavLinkProps = Omit<LinkHTMLAttributes<HTMLAnchorElement>, "className"> & {
  children?: ReactNode;
  path: string;
  className?: string | ((props: { isActive: boolean }) => string);
};

Navigate

interface NavigateProps {
  path: string;
}

Outlet

export interface OutletProps {
  route?: ConfigRoute;
}

Router

export interface RouterProps {
  routes: ConfigRoute[];
}
1.1.8

1 year ago

1.1.6

1 year ago

1.1.5

1 year ago

1.1.4

1 year ago

1.1.3

1 year ago

1.1.0

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago