Angular新手部署Firebase应用后显示默认页面问题求助
Hey there! I’ve helped a lot of Angular newbies work through this exact Firebase Hosting issue—let’s get your app showing up instead of that default welcome page. Here’s what to check step by step:
Double-check your Angular build output
First, make sure your local build is generating the right files. Runng build(useng build --prodif you’re on an older Angular version) and navigate to thedistfolder. Open theindex.htmlfile inside—does it have your app’s content, not Firebase’s welcome message? Also, note that newer Angular versions build into a subfolder underdist(likedist/your-app-name), so don’t miss that detail.Verify your Firebase Hosting path
Open yourfirebase.jsonfile and look at thehosting.publicvalue. This needs to point directly to your Angular app’s build folder. For example, if your app is namedangular-todo-app, the path should be"dist/angular-todo-app"—not just"dist". If this is wrong, Firebase can’t find your app’s index.html and falls back to the default page.Force a clean deployment to bypass caching
Sometimes cached files can keep the default page visible even after you’ve uploaded your app. Try redeploying with the--forceflag to ensure fresh files are uploaded:firebase deploy --only hosting --forceYou can also test locally first with
firebase serve—if the local preview shows your app correctly, the issue is almost certainly related to deployment caching or incorrect path configuration.Compare local and Firebase index.html files
Head to your Firebase Console, go to the Hosting section, and use the file browser to view the rootindex.htmlfile. Compare it to the one in your localdistfolder. If they don’t match, that means the wrong files were uploaded. Re-run the build command and make sure you’re deploying from the correct directory.Check your single-page app rewrite rules
Since you configured Firebase for a single-page app, confirm yourfirebase.jsonhas the correct rewrite setup. It should look something like this:"hosting": { "public": "dist/your-app-name", "ignore": [ "firebase.json", "**/.*", "**/node_modules/**" ], "rewrites": [ { "source": "**", "destination": "/index.html" } ] }While missing rewrites usually cause routing issues (not the default page), it’s worth confirming this is set up right just in case.
Give these steps a try—chances are one of them will fix the problem! 😊
内容的提问来源于stack exchange,提问作者Vini

