diff --git a/crates/axum_bundler/src/bundle.rs b/crates/axum_bundler/src/bundle.rs index 1af5f3a5..67fd4a1f 100644 --- a/crates/axum_bundler/src/bundle.rs +++ b/crates/axum_bundler/src/bundle.rs @@ -39,7 +39,15 @@ async fn main() { async fn catch_all(uri: Uri) -> Html { dbg!(&uri.path()); - let result = SSR.with(|ssr| ssr.borrow_mut().render_to_string(Some(&uri.path()))); + let path = &uri.path(); + + let payload = format!( + r#"{{ + "path": "{path}" + }}"# + ); + + let result = SSR.with(|ssr| ssr.borrow_mut().render_to_string(Some(&payload))); match result { Ok(html) => Html(html), diff --git a/packages/tuono-router/src/components/Matches.tsx b/packages/tuono-router/src/components/Matches.tsx index 66111b84..166eac1b 100644 --- a/packages/tuono-router/src/components/Matches.tsx +++ b/packages/tuono-router/src/components/Matches.tsx @@ -4,15 +4,19 @@ import { useRouterStore } from '../hooks/useRouterStore' import { RouteMatch } from './RouteMatch' import NotFound from './NotFound' -export const Matches = React.memo(function () { +interface MatchesProps { + serverPath?: string +} + +export function Matches({ serverPath }: MatchesProps): JSX.Element { const location = useRouterStore((st) => st.location) const router = useRouter() - const route = router.routesById[location?.pathname || ''] + const route = router.routesById[location?.pathname || serverPath || ''] if (!route) { return } return -}) +} diff --git a/packages/tuono-router/src/components/RouterProvider.tsx b/packages/tuono-router/src/components/RouterProvider.tsx index b6c0383c..fe12cd24 100644 --- a/packages/tuono-router/src/components/RouterProvider.tsx +++ b/packages/tuono-router/src/components/RouterProvider.tsx @@ -40,10 +40,14 @@ function RouterContextProvider({ interface RouterProviderProps { router: Router + serverProps: { + path?: string + } } const initRouterStore = (): void => { const updateLocation = useRouterStore((st) => st.updateLocation) + useLayoutEffect(() => { const { pathname, hash, href, search } = window.location updateLocation({ @@ -58,12 +62,14 @@ const initRouterStore = (): void => { export function RouterProvider({ router, + serverProps, ...rest }: RouterProviderProps): JSX.Element { initRouterStore() + return ( - + ) } diff --git a/packages/tuono-router/src/hooks/useRouterStore.tsx b/packages/tuono-router/src/hooks/useRouterStore.tsx index e7af31a7..ba3cb443 100644 --- a/packages/tuono-router/src/hooks/useRouterStore.tsx +++ b/packages/tuono-router/src/hooks/useRouterStore.tsx @@ -4,7 +4,7 @@ import { create } from 'zustand' export interface ParsedLocation { href: string pathname: string - search: URLSearchParams + search?: URLSearchParams searchStr: string hash: string } @@ -27,8 +27,8 @@ export const useRouterStore = create()((set) => ({ status: 'idle', location: { href: '', - pathname: '/', - search: {}, + pathname: '', + search: undefined, searchStr: '', hash: '', },