Bird
0
0

Which of the following is the correct way to access the tenant ID from a request URL in a Remix loader?

easy📝 Syntax Q3 of 15
Remix - Advanced Patterns
Which of the following is the correct way to access the tenant ID from a request URL in a Remix loader?
Aconst tenantId = request.body.tenantId;
Bconst url = new URL(request.url); const tenantId = url.hostname.split('.')[0];
Cconst tenantId = window.location.hostname;
Dconst tenantId = request.headers.get('tenant-id');
Step-by-Step Solution
Solution:
  1. Step 1: Understand request URL parsing in loaders

    Loader runs server-side, so you can parse request.url to get hostname and extract tenant ID.
  2. Step 2: Check other options

    request.body is not available in GET requests. window is client-side only. Headers may not contain tenant info unless explicitly set.
  3. Final Answer:

    const url = new URL(request.url); const tenantId = url.hostname.split('.')[0]; -> Option B
  4. Quick Check:

    Tenant ID from hostname = URL parsing [OK]
Quick Trick: Parse request.url hostname to get tenant ID in loader [OK]
Common Mistakes:
MISTAKES
  • Using client-side window object in server code
  • Assuming tenant ID is in request body for GET
  • Relying on headers without setting them

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Remix Quizzes