[Angular2 Router] Understand the Angular 2 Base href Requirement
Angular The Router base Angular2 href Understand
2023-09-14 09:00:53 时间
The <base href=”/”/>
you define will determine how all other assets you plan on loading treat their relative paths. While you’ll most often use /
as your base href, it’s important to understand what’s going on in case you need to change how you’re hosting your project.
If the base href is not set, app will have error. The easiest way to do it set base href in html:
<!doctype html> <html> <head> <meta charset="utf-8"> <title>WikiSearch</title> <base href="/"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="icon" type="image/x-icon" href="favicon.ico"> </head> <body> <app-root>Loading...</app-root> </body> </html>
Sometimes though, coders of an Angular application don’t have access to the head section of the
application HTML. This is true for instance, when reusing headers and footers of a larger, preexisting
application.
Fortunately there is a workaround for this cases. You can declare the application base path
programmatically, when bootstrapping the Angular application:
@NgModule({ declarations: [ AppComponent ], imports: [ appRoutes, BrowserModule, FormsModule, HttpModule, JsonpModule, SharedServiceModule.forRoot() ], providers: [ {provide: APP_BASE_HREF, useValue: '/'}, { provide: API_URL, useValue: `https://en.wikipedia.org/w/api.php?callback=JSONP_CALLBACK` } ], bootstrap: [AppComponent] }) export class AppModule { }
相关文章
- 前端人员该怎么面试 经典Angular面试题有哪些[通俗易懂]
- angular基础面试题_java web面试题
- orbital angular momentum_omnidirectional
- Angular 应用里 index.html 的作用
- 关于 Angular 应用的入口
- 关于 Angular Universal 应用执行时需要 Browser API 的问题
- Angular Universal Application 应该处理 HTTP POST 请求吗?
- Angular RouterModule.forRoot(ROUTES) 和 forChild(ROUTES)的区别
- 【Angular教程】-组件通信|8月更文挑战
- 【错误记录】Android Studio 创建报错 ( The length of the module location exceeds the limit of 100 characters. )
- Angular 依赖注入错误消息:ERROR Error NullInjectorError No provider for XX
- 关于 Angular 12 的 inlineCriticalCss 选项
- ORA-31691: The worker received message number string from the MCP, which is invalid. ORACLE 报错 故障修复 远程处理
- ORA-38408: The ADT “string” does not exist in the current schema. ORACLE 报错 故障修复 远程处理
- ORA-48411: The trace files exceeds the maximum number [string] ORACLE 报错 故障修复 远程处理
- ORA-48485: The file exceeds the maximum length [string] ORACLE 报错 故障修复 远程处理
- the cloudTaking Oracle to the Cloud: The Evolution of Database Systems(oracleisin)
- Angular 框架将进入 2.0 时代