请为APP_BASE_HREF令牌异常Angular2提供一个值 [英] please provide a value for APP_BASE_HREF token exception Angular2

查看:36
本文介绍了请为APP_BASE_HREF令牌异常Angular2提供一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发第一个Angular 2应用程序,并具有以下代码

I am developing the first Angular 2 application and have the following code

AppModule.ts代码

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';

import {RouterModule} from '@angular/router';

import { AppComponent }  from './app.component';
import { MenuComponent} from './home/menu/menu.component';
import { FooterComponent} from './home/footer/footer.component';
import { AboutComponent} from './personalDetails/about/about.component';
@NgModule({
  imports:  [ 
              BrowserModule,
              RouterModule.forRoot([
                  {path: '' , component : AboutComponent},
                  {path: 'about' , component : AboutComponent}

                ])
            ],
  declarations: [ 
                AppComponent, 
                MenuComponent, 
                FooterComponent,
                AboutComponent,


                ],
  bootstrap: [ AppComponent ]
})
export class AppModule { }

AppComponent.ts 代码

import { Component } from '@angular/core';

@Component({
    selector: 'app',
    template:   `
                <menu></menu>
                <router-outlet></router-outlet>
                <footer></footer>

                `

})
export class AppComponent { }

我的控制台显示以下错误

My console says the following error

推荐答案

修复很简单,我忘了在index.html中添加基本href标记,

The fix is simple and I forgot to add the base href tag in the index.html,

<base href="/"/>

当我研究为什么我们默认情况下应该添加基本href时(在angular1中不是这种情况).我发现了以下

When I researched why should we add base href by default which is not the case in angular1. I found the following

  1. 通过默认,Angular2使用 HTML5
  2. 不需要哈希符号.
  3. URL重写是必需的,如果该应用程序在每个服务器上运行的任何服务器中均不相同,并且可以在文档中找到,而该文档对于
  1. By default Angular2 uses HTML5
  2. No hash symbol is needed.
  3. URL Rewriting is necessary, if the application runs in any of the server which are different for each server and can be found in the documentation which are separate for Tomcat, IIS etc.

这篇关于请为APP_BASE_HREF令牌异常Angular2提供一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆