From c6c3973a7246e6b5f4fccc77c9f117d56f04943e Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 21 Oct 2025 19:39:10 -0500 Subject: [PATCH] NetlifyAdapter: use a default _redirects with SPA routing --- src/lib/deploy/NetlifyAdapter.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/lib/deploy/NetlifyAdapter.ts b/src/lib/deploy/NetlifyAdapter.ts index 2d4b5b8a..cda63425 100644 --- a/src/lib/deploy/NetlifyAdapter.ts +++ b/src/lib/deploy/NetlifyAdapter.ts @@ -69,6 +69,9 @@ export class NetlifyAdapter implements DeployAdapter { const zip = new JSZip(); await this.addDirectoryToZip(distPath, zip); + // Ensure _redirects file exists for SPA routing + await this.ensureRedirectsFile(distPath, zip); + // Generate ZIP blob const zipBlob = await zip.generateAsync({ type: 'blob' }); @@ -175,4 +178,25 @@ export class NetlifyAdapter implements DeployAdapter { console.warn(`Failed to read directory ${dirPath}`); } } + + /** + * Ensures _redirects file exists in the deployment for SPA routing + * If not present in dist directory, adds it to the ZIP with default content + */ + private async ensureRedirectsFile(distPath: string, zip: JSZip): Promise { + const redirectsPath = `${distPath}/_redirects`; + + try { + // Check if _redirects file already exists + const stat = await this.fs.stat(redirectsPath); + if (!stat.isFile()) { + throw new Error('_redirects is not a file'); + } + // File exists, no need to add it (already added by addDirectoryToZip) + } catch { + // File doesn't exist, add default _redirects to ZIP + const defaultRedirects = '/* /index.html 200'; + zip.file('_redirects', defaultRedirects); + } + } }