@app-studio/components
Router
Render a route from the shared history store. Navigate between screens and optionally synchronize the browser address bar.
View component sourceImport
ts
import { Router } from '@app-studio/components';New to the library? Complete installation and provider setup first.
Interactive examples
Try the component, then open Code to copy the complete example.
import React from 'react';
import { Text, Vertical, Horizontal, View } from 'app-studio';
import { Button, Router, useHistory } from '@app-studio/components';
const Home = () => {
const { push } = useHistory();
return (
<Vertical gap={12} padding={16}>
<Text fontWeight="bold">Home</Text>
<Button onClick={() => push('/profile/42')}>Go to profile 42</Button>
</Vertical>
);
};
const Profile = ({ id }: { id?: string }) => {
const { back, canGoBack } = useHistory();
return (
<Vertical gap={12} padding={16}>
<Text fontWeight="bold">Profile #{id}</Text>
<Button variant="outline" isDisabled={!canGoBack} onClick={() => back()}>
Back
</Button>
</Vertical>
);
};
/**
* A tiny two-screen app driven by the shared history store. On native the
* Android hardware Back button maps to `back()` automatically.
*/
export const DefaultRouter = () => (
<View
height={240}
width="100%"
maxWidth={360}
borderRadius={16}
overflow="hidden"
borderWidth={1}
borderStyle="solid"
borderColor="color-gray-200"
>
<Horizontal padding={8} backgroundColor="color-gray-100">
<Text color="color-gray-500">Mini Router demo</Text>
</Horizontal>
<Router
initialPath="/"
routes={[
{ path: '/', component: Home },
{ path: '/profile/:id', component: Profile },
]}
/>
</View>
);Props
Required props are marked below. A dash indicates an unspecified default. Design system configuration can override implementation defaults.
Scroll horizontally to see every column.
| Prop | Type | Default | Description |
|---|---|---|---|
routes Required | RouteConfig[] | Record<string, React.ComponentType<any>> | — | See the type and source declaration for this property.Source |
initialPath | string | — | See the type and source declaration for this property.Source |
notFound | React.ComponentType<any> | — | See the type and source declaration for this property.Source |
syncBrowserHistory | boolean | false | Reflect navigation to the browser URL and honour the browser Back button (web only, default false). Native always honours the hardware Back button.Source |
For shared layout, color, and responsive properties, read Styling & composition and Responsive layouts. Additional native element attributes depend on the target platform.
Usage guidance
- Give controls a visible label or an accessible name, and verify keyboard interaction. See Accessibility.
- For controlled inputs, update the value from the callback shown in the props table. Keep application state in your component or form library.
- These previews run in the browser. Check React Native setup for platform requirements and differences.