Discover why direct linking causes errors in Lovable routes, learn how to enable them, and follow best practices for direct URL access.

Book a call with an Expert
Starting a new venture? Need to upgrade your web app? RapidDev builds application with your growth in mind.
Direct linking to routes fails in Lovable because the preview/hosting environment serves static files without the server-side rewrite behavior (index.html fallback) that client-side routers expect, and because some frameworks require a server/SSR runtime that isn’t provided by Lovable’s static preview. In short: a browser GET for /some/path expects the host to return your SPA’s index.html (so the client router can mount), but Lovable’s preview and default static hosting don’t automatically rewrite every unknown path to index.html, and apps that rely on server-only rendering or API routes will also error when requested directly.
// Prompt 1: Find client-side router usage
// Search project files and show the exact import/use sites for BrowserRouter, HashRouter, or other routers.
Please search the repo for "BrowserRouter", "HashRouter", "createBrowserRouter", "createHashRouter", "RouterProvider", and "react-router-dom". For each match:
- show the file path and the 6 lines before/after the match,
- indicate which router is used (BrowserRouter vs HashRouter vs server router),
- explain in one sentence whether that router requires an index.html fallback for direct linking.
// Prompt 2: Check build/hosting config that affects fallback and base path
// Inspect vite.config.js, webpack config, package.json scripts, public/_redirects, netlify.toml, vercel.json, and any static.json.
Please open vite.config.js, package.json, public/_redirects, netlify.toml, vercel.json, and any file named static.json or build config files. For each:
- show relevant sections (base, build, rewrites, redirects),
- explain whether a fallback rewrite to index.html or a base path is configured or missing,
- list exact file paths that would need change to provide a fallback (only diagnosing — do not change files).
// Prompt 3: Detect server/SSR framework usage
// Look for Next.js, Remix, SvelteKit, or express server files that indicate server runtime requirements.
Please search for "next.config.js", "remix.config", "svelte.config.js", "server.js", "app router", or "pages/api". For each framework detected:
- explain if it requires a Node server or special adapter for direct route requests,
- list which routes or features will fail in a static preview (API routes, getServerSideProps, server actions).
This prompt helps an AI assistant understand your setup and guide you through the fix step by step, without assuming technical knowledge.
Enable direct linking by either switching your SPA to client-side hash routing (works entirely inside Lovable) or by adding host rewrite rules (create \_redirects / vercel.json / 404.html in the repo and then sync/publish to your host). Use HashRouter if you want a fix you can implement and test entirely inside Lovable without touching external deployment settings.
// Paste into Lovable chat (Chat Mode) and ask Lovable to edit files.
// Task: Replace BrowserRouter with HashRouter so routes work on direct links without server rewrites.
// Update file: src/main.jsx (or src/index.jsx / src/main.tsx / src/index.tsx)
// Find the top-level router wrapper and change the import and JSX.
Update src/main.jsx:
- Replace "import { BrowserRouter } from 'react-router-dom'" with "import { HashRouter } from 'react-router-dom'".
- In the ReactDOM.render / createRoot render tree, replace <BrowserRouter>...</BrowserRouter> with <HashRouter>...</HashRouter>.
```jsx
// // Example changed content (Lovable: make the actual edit in the file)
import React from 'react'
// // Keep existing imports
import { HashRouter } from 'react-router-dom'
import App from './App'
import { createRoot } from 'react-dom/client'
const root = createRoot(document.getElementById('root'))
root.render(
<HashRouter>
<App />
</HashRouter>
)
// After edit: run Lovable Preview and confirm navigation and direct-linking to routes works.
<ul>
<li><b>Option B — Add hosting rewrite files (create repo files; deploy via GitHub / host)</b></li>
</ul>
// Paste into Lovable chat (Chat Mode) and ask Lovable to create these files in the repo.
// Note: after adding, use Lovable's GitHub sync/export and deploy on Netlify/Vercel/GitHub Pages as usual.
// Create file: public/_redirects
/* /index.html 200
// Create file: vercel.json
{
"rewrites": [
{ "source": "/(.*)", "destination": "/index.html" }
]
}
// Create file: public/404.html (simple SPA fallback for GitHub Pages)
// This file should live in public/ so the built 404 is served by GitHub Pages.
// After adding files: use Lovable's GitHub Sync / Export to push to your repo, then deploy on the host (Netlify/Vercel/GitHub Pages).
// Deploy step is outside Lovable if your host needs a connected repo or dashboard action.
```
Direct answer: Use a client-side-safe routing mode (hash routing) or add a server-side rewrite/redirect that returns index.html for unknown paths. In Lovable you can implement the client-side changes directly (recommended for quick fixes), and you can add hosting redirect files in the repo (so they travel with GitHub export). If you must change host settings (Vercel/Netlify/etc.), create the redirect files in Lovable and then deploy on your provider — that last step happens outside Lovable.
Why: Hash routing avoids any server rewrite requirement. This is fully implementable inside Lovable's editor and Publish flow and fixes direct URL access for SPAs without touching hosting.
Paste this prompt into Lovable’s chat to implement React HashRouter change:
// Update src/main.jsx (or src/index.jsx) to use HashRouter
// If src/main.jsx doesn't exist, check src/App.jsx or src/index.jsx and adjust path names below.
Please modify the router setup to use HashRouter so direct URL access works without server rewrites.
- Open file: src/main.jsx
- Replace any import of BrowserRouter with HashRouter from 'react-router-dom'.
- Wrap the app with <HashRouter> where currently <BrowserRouter> is used.
Show me the diff and update any other file that still imports BrowserRouter (for example src/App.jsx or src/routes.jsx). If tests/imports reference BrowserRouter, change them to HashRouter too.
Paste this prompt into Lovable’s chat to implement Vue hash routing:
// Update src/router/index.js (or src/router.js) to use hash history
// If the router file uses createWebHistory, switch to createWebHashHistory.
Please edit src/router/index.js (or the existing router file) to use hash mode:
- Replace createWebHistory(...) with createWebHashHistory(...)
- Ensure router is exported as before.
Show me the diff and run a quick sanity check of routes in Preview.
Why: Some hosting providers prefer server-side rewrites so BrowserRouter works. You can add redirect configuration files inside Lovable; deploying them to your host may require provider steps outside Lovable.
public/\_redirects with a rule to rewrite all routes to index.html.vercel.json with a rewrite rule; committing from Lovable to GitHub will include it for Vercel to honor on deploy.
Paste this prompt into Lovable’s chat to add Netlify and Vercel redirect files:
// Create redirect files to enable SPA fallbacks on hosts that use these files.
// File: public/_redirects
// File contents:
// /* /index.html 200
// File: vercel.json
// File contents:
// {
// "rewrites": [
// { "source": "/(.*)", "destination": "/index.html" }
// ]
// }
Please create the two files above at public/_redirects and vercel.json with exact contents shown. Add a short comment in each file as a reminder which host uses it. Show me the diff.
Use this single prompt if you want Lovable to apply the right fix depending on framework:
// Apply best practice for direct URL access
// Check project type: React or Vue (or other). Then apply the appropriate change.
Please:
- Detect if this is a React project (presence of react-router-dom). If yes, change BrowserRouter to HashRouter in src/main.jsx or src/App.jsx and show the diff.
- Detect if this is a Vue project (presence of vue-router). If yes, change createWebHistory to createWebHashHistory in src/router/index.js and show the diff.
- Add public/_redirects and vercel.json files as described (only if they don't already exist).
- Run Preview and report any client-side console errors.
If a change might affect tests or CI files, do NOT edit them; list those files and explain the required follow-up steps.
Notes: Using HashRouter is the simplest reliable fix you can do fully inside Lovable. Adding redirect files is safe to add in Lovable and will travel with GitHub sync, but actual provider deploy or settings may require action outside Lovable (deploy via your host or confirm the provider picks up the new file).
From startups to enterprises and everything in between, see for yourself our incredible impact.
Need a dedicated strategic tech and growth partner? Discover what RapidDev can do for your business! Book a call with our team to schedule a free, no-obligation consultation. We’ll discuss your project and provide a custom quote at no cost.