Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Route wrapper for typescript #465

Merged
merged 4 commits into from
Apr 6, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ render(<Main />, document.body);

If there is an error rendering the destination route, a 404 will be displayed.

#### Caveats

Because the `path` and `default` props are used by the router, it's better to avoid
same props in your components.
rschristian marked this conversation as resolved.
Show resolved Hide resolved

### Handling URLS

:information_desk_person: Pages are just regular components that get mounted when you navigate to a certain URL.
Expand Down Expand Up @@ -276,6 +281,26 @@ function App() {
render(<App />, document.body);
```

### `Route` Component

Alternatively to adding the router props (`path`, `default`) directly to your component, you may want to use the `Route` component we provide instead. This tends to appease TypeScript, while still passing down the routing props into your component for use.

```js
import { Router, Route } from 'preact-router';

function App() {
let users = getUsers();

return (
<Router>
<Route path="/" component={Home} />
{/* Route will accept any props of `component` type */}
<Route path="/users" component={Users} users={users} />
</Router>
);
}
```

### License

[MIT](./LICENSE)