T
TanStack16mo ago
stormy-gold

Easiest way to make the possible routes/paths accessible when browsing it directly

First things first Im a newbie on building websites in general and I know that this can be a Vite question (but Im not so sure). Also I know this is a very Googleable question but I have no idea on what to search, so feel free to provide me some terminology on this. Basically I want to make my route domain.com/user accessible without necessarily navigating to the domain.com before to manually go to the /user route. Of course, on development build works fine but not in prod, probably because of some config that Im missing. Am i able to trivially achieve this using tanstack router / vite ?
4 Replies
diverse-rose
diverse-rose16mo ago
Could you elaborate more on the issue? If you're discussing implementing a permanent redirect from the root URL to '/users', you can achieve this by configuring a permanent redirect in the root route file export const Route = createFileRoute("/")({ beforeLoad: async ({ location }) => { throw redirect({ to: "/users", search: { ...location.search }, }); }, }); this part: "search: { ...location.search }" ensures that any search params passed are preserved during the redirect
stormy-gold
stormy-goldOP16mo ago
Sorry if I’m not being clear, is the lack of knowledge on my part. What I want is not a redirect, my problem is that the route /user exists but if I access it directly (like clicking the link domain.com/user and open it on the browser) I will end up with a 404 error, but the page exists. If I access first the domain then clicking a button to navigate to /user then it works fine. This only on production build.
diverse-rose
diverse-rose16mo ago
Are you using file-based or code-based routing ?
stormy-gold
stormy-goldOP16mo ago
File-based routing

Did you find this page helpful?