Angular静态落地页配置:登录注册跳转、SPA引导及Nginx部署问题咨询
Angular 静态落地页配置问题(Nginx 部署场景)
需求目标
当前正在学习Angular,使用Nginx部署项目,想要实现的效果:
- 做一个独立的静态HTML落地页,页面包含两个按钮,分别跳转至
/login和/signup路由 - 跳转至上述路由后,再正常引导加载Angular单页应用,挂载
app-root根组件启动整个SPA
已尝试的操作
- 在项目内与
index.html同级的位置新建landing.html作为落地页文件,尝试修改angular.json的构建配置,将默认入口的index字段从src/index.html调整为src/landing.html,对应配置片段:"architect": { "build": { "builder": "@angular-devkit/build-angular:browser", "options": { "outputPath": "dist/", "index": "src/index.html", // 尝试修改为src/landing.html "main": "src/main.ts", - 看过其他相关方案提到直接将
index.html用作静态页面,但无法理解这种模式下,后续如何加载用于引导SPA的app-root组件 - 尝试从
index.html中移除app-root标签后,页面显示空白,控制台抛出如下错误:Error: The selector "app-root" did not match any elements at DefaultDomRenderer2.selectRootElement (vendor.js:201546) at BaseAnimationRenderer.selectRootElement (vendor.js:141558) at locateHostElement (vendor.js:170017) at ComponentFactory$1.create (vendor.js:188576) at ApplicationRef.bootstrap (vendor.js:194164) at vendor.js:193812 at Array.forEach (<anonymous>) at PlatformRef._moduleDoBootstrap (vendor.js:193811) at vendor.js:193770 at ZoneDelegate.invoke (polyfills.js:572)
待解答的核心疑问
- 静态落地页应该配置在项目的什么位置
- 点击登录/注册按钮跳转后,引导启动Angular SPA的实现逻辑是什么
- 对应的Nginx部署配置该如何编写
补充说明
- 目前没有配置独立的LandingModule,也没有使用
this.router.url == '/landing'或this.router.url == '/index'这类路由判断逻辑做分流
内容的提问来源于stack exchange,提问作者Lou
相关产品推荐
相关产品推荐

