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

docs: Document the <Link> path property. #366

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all 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
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,32 @@ render(
)
```

`<Link>` accepts an optional `path` prop so you can choose to apply the active class for any arbitrary URL pattern that does not exactly match the link's `href` prop. This is excellent for nested navigation.

```js
import { Router } from 'preact-router';
import { Link } from 'preact-router/match';

render(
<div>
<nav>
<Link activeClassName="active" href="/foo" path="/foo/:biz?">Foo</Link>
</nav>
<Router>
<div path="/foo/:bar?">
This is the Foo route.
<Link activeClassName="active" href="/foo">Bar</Link>
<Link activeClassName="active" href="/foo/biz">Biz</Link>
<Link activeClassName="active" href="/foo/baz">Baz</Link>
<Router>
<div path="/foo">This is the Foo Bar route.</div>
<div path="/foo/biz">This is the Foo Biz route.</div>
<div path="/foo/baz">This is the Foo Baz route.</div>
</div>
</Router>
</div>
)
```

### Default Link Behavior

Expand Down