useApp

Read the routing context inside an <App>. Returns the resolved Config, the pages map, and live values from React Router (current path, matched route, params, navigation helper).

import { useApp } from "@reacteditor/core";
 
const PageTitle = () => {
  const { matched } = useApp();
  if (!matched) return null;
  return <h1>You are on {matched.route}</h1>;
};

useApp must be called from a component rendered inside <App> (or <AppProvider>). Calling it outside throws.

Returns

PropertyTypeDescription
configConfigThe shared config passed to <App>.
pagesRecord<string, Data>The pages map passed to <App>.
routesstring[]All page route keys, in declaration order.
editorPathstring | nullThe configured editor URL prefix. null if editor mode is disabled.
currentPathstringThe live pathname from React Router.
isEditingbooleantrue when currentPath is under editorPath.
matchRoutestringThe path to match against pages — equal to currentPath, but stripped of editorPath if editing.
matchedAppMatched | nullThe matched page, or null for a 404. See AppMatched.
navigate(route: string) => voidNavigate to a route key. Wraps with editorPath automatically while editing.

AppMatched

PropertyTypeDescription
routestringThe route key from pages that matched (e.g. "/products/:handle").
paramsRecord<string, string | undefined>Concrete URL params (e.g. { handle: "abc" }).
dataDataThe page data for the matched route.

Example: navigating between pages

import { useApp } from "@reacteditor/core";
 
const PageSwitcher = {
  render: () => {
    const { routes, navigate, matched } = useApp();
    return (
      <select
        value={matched?.route ?? ""}
        onChange={(e) => navigate(e.target.value)}
      >
        {routes.map((r) => (
          <option key={r} value={r}>
            {r}
          </option>
        ))}
      </select>
    );
  },
};