Skip to content

Commit

Permalink
API for clientside router (#8571)
Browse files Browse the repository at this point in the history
* refactored CSR into goto() function

* first refectoring for router API

* added test

* added comments to fixture

* rename + preliminary changeset

* changeset: now 'minor' and featuring Mathew's example from the docs

* moved for simpler diff

* update after #8617

* fixed ts-errors

* more comprehensible handling of intra-page state

* sync with main

* synch from next_tm
  • Loading branch information
martrapp authored Sep 27, 2023
1 parent 9fe4b95 commit 63bc37f
Show file tree
Hide file tree
Showing 9 changed files with 586 additions and 434 deletions.
17 changes: 17 additions & 0 deletions .changeset/fresh-pots-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
'astro': minor
---

View transitions can now be triggered from JavaScript!

Import the client-side router from "astro:transitions/client" and enjoy your new remote control for navigation:

```js
import { navigate } from 'astro:transitions/client';

// Navigate to the selected option automatically.
document.querySelector('select').onchange = (ev) => {
let href = ev.target.value;
navigate(href);
};
```
7 changes: 7 additions & 0 deletions packages/astro/client.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ declare module 'astro:transitions' {
export const ViewTransitions: ViewTransitionsModule['default'];
}

declare module 'astro:transitions/client' {
type TransitionRouterModule = typeof import('./dist/transitions/router.js');
export const supportsViewTransitions: TransitionRouterModule['supportsViewTransitions'];
export const transitionEnabledOnThisPage: TransitionRouterModule['transitionEnabledOnThisPage'];
export const navigate: TransitionRouterModule['navigate'];
}

declare module 'astro:middleware' {
export * from 'astro/middleware/namespace';
}
Expand Down
Loading

0 comments on commit 63bc37f

Please sign in to comment.