What happens when a user visits /profile in a single-page app?
medium
A. The server returns a 404 error because /profile does not exist
B. The server serves the index.html file so the app can handle the route
C. The server redirects the user to the homepage URL
D. The server serves a blank page
Solution
Step 1: Understand the rewrite rule
The rule sends all requests (**) to /index.html, regardless of the URL path.
Step 2: Apply to /profile URL
When user visits /profile, Firebase Hosting serves index.html, letting the app's JavaScript handle the route.
Final Answer:
The server serves the index.html file so the app can handle the route -> Option B
Quick Check:
Rewrite all URLs to index.html = The server serves the index.html file so the app can handle the route [OK]
Hint: Rewrite '**' to index.html serves all app routes [OK]
Common Mistakes:
Expecting 404 error for app routes
Thinking server redirects to homepage
Assuming blank page is served
4. A developer sets up Firebase Hosting but their single-page app shows a 404 error on routes like /dashboard. What is the likely fix?
medium
A. Add a rewrite rule in firebase.json to send all routes to /index.html
B. Remove the index.html file from the hosting folder
C. Disable HTTPS in Firebase Hosting settings
D. Change the app to use multiple HTML files for each route
Solution
Step 1: Identify cause of 404 on app routes
Without rewrite rules, Firebase Hosting looks for actual files matching the URL and returns 404 if missing.
Step 2: Apply rewrite rule fix
Adding a rewrite rule to send all routes to /index.html lets the app handle routing and prevents 404 errors.
Final Answer:
Add a rewrite rule in firebase.json to send all routes to /index.html -> Option A
Quick Check:
Rewrite rule fixes 404 on SPA routes [OK]
Hint: Rewrite all routes to index.html to fix SPA 404 errors [OK]
Common Mistakes:
Deleting index.html file
Disabling HTTPS thinking it helps
Using multiple HTML files instead of SPA routing
5. You want your Firebase Hosting to serve a React single-page app that uses client-side routing. Which configuration ensures all URLs load your app correctly?
hard
A. Disable rewrites and rely on default file serving
B. Upload separate HTML files for each route like /about.html and /contact.html
C. Set a rewrite rule in firebase.json to send all requests to /index.html
D. Use HTTP instead of HTTPS to avoid routing issues
Solution
Step 1: Understand React SPA routing needs
React SPA uses client-side routing, so all URLs must load the same index.html to let JavaScript handle routes.
Step 2: Configure Firebase Hosting rewrites
Adding a rewrite rule sending all requests to /index.html ensures the app loads correctly on any URL.
Final Answer:
Set a rewrite rule in firebase.json to send all requests to /index.html -> Option C
Quick Check:
Rewrite all URLs to index.html for SPA routing [OK]
Hint: Rewrite all URLs to index.html for React SPA [OK]
Common Mistakes:
Uploading multiple HTML files for SPA routes
Disabling rewrites causing 404 errors
Switching to HTTP thinking it fixes routing
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.