Support Client-Only routes. #947
Replies: 3 comments 10 replies
-
Gatsby is a React framework, so you'd have client side logic too, out of the box. Astro doesn't impose any client decisions. So if you want to have a mini spa, you can already do this today by using a dynamic route, and render your client side framework there. |
Beta Was this translation helpful? Give feedback.
-
The docs state that it is possible "Static sites can include Astro islands for interactive UI components or even entire embedded client-side rendered apps! written in the UI framework of your choice in an otherwise static, pre-rendered page". But doesn't provide any information on how to achieve it. Not sure how it can be done when dynamic routes in static mode must export the getStaticPaths function and all paths need to be known at build time. Here's my code that currently only works if the page is not pre-rendered. This is in ---
export const prerender = false
import BaseLayout from "../../components/BaseLayout.astro";
import App from '../../components/App.jsx'
---
<BaseLayout>
<App client:only="solid-js" />
</BaseLayout> And a simplified version of my App component is: import { Router, Route } from "@solidjs/router";
import Layout from './Layout'
import Todos from './Todos'
import Todo from './Todo'
import Profile from './Profile'
export default function App() {
return (
<Router root={Layout}>
<Route path="/app/todos" component={Todos} />
<Route path="/app/todos/:id" component={Todo} />
<Route path="/app/profile" component={Profile} />
</Router>
)
} |
Beta Was this translation helpful? Give feedback.
-
Finally found that it was an issue with my redirects on deployment because of trailing slashes. Closing the discussion. |
Beta Was this translation helpful? Give feedback.
-
Summary
Astro requires SSR for parameterized routes to be resolved dynamically. This should be possible without the need of SSR with client-only routes. As seen in GatsbyJS and NextJS
Background & Motivation
I want to have a 100% static site with a few routes that are behind authentication and communicate with a Supabase database. This is currently possible in Gatsby using "client-only routes" and I also believe it's possible using the Pages router in Next and coming soon to their App router.
It would remove the need for adapters in this use case where SSR is otherwise not wanted.
Goals
To be able to have dynamic routes controlled by an SPA router that takes over any routes. For example a page at /app/[...].astro could just render an component with react-router, solid-router etc and the client-only directive. The [...] syntax is what gatsby uses. Hosting would also need to configure any redirects from /app/* to /app/[...]/index.html. But it seems like it should be doable with Astro.
Are there any roadblocks in implementing this?
Beta Was this translation helpful? Give feedback.
All reactions