React router 7 SSR relative url support in fetch or any workaround #13292
Unanswered
gopal-freshwork
asked this question in
Q&A
Replies: 1 comment
-
Server-side fetch can't have a relative URL because there's no context of what's the host, you could have to somehow tie the fetch with the But instead of doing fetch to another route, which involves:
You could simplify all of that and call a function. Create a function If you still want relative |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
I’m working on a POC where I’ve developed a common API interface to handle API calls, along with interceptors to manage responses.
However, when making an API call, I currently need to use an absolute URL:
We have multiple customer domain accounts, and based on the customer, we retrieve specific details. Because of this, we can’t use absolute URLs.
When I try using a relative URL:
I encounter the following error:
I’ll be using this API interface in loaders, actions, and button click events, etc
• In loaders and actions, I have access to the request object, so I can retrieve the domain from it.
• However, in cases like button clicks or anywhere, I don’t have direct access to the request.
Is there a way to use relative URLs in this scenario, or any workaround to resolve this issue?
Eg:
Repo:
Loader request: https://github.com/gopal-freshwork/react-rr7-poc/blob/main/app/routes/home.tsx#L12
Button onClick API: https://github.com/gopal-freshwork/react-rr7-poc/blob/main/app/routes/home.tsx#L26
API client Host setting: https://github.com/gopal-freshwork/react-rr7-poc/blob/main/app/api/apiClient.ts#L7
Beta Was this translation helpful? Give feedback.
All reactions