【发布时间】:2016-10-28 01:25:59
【问题描述】:
我正在构建我的第一个 Angular 2 应用程序,现在我已经有了一个不错的 Webpack 构建系统、路由、服务和组件。
我尝试在我的一个组件中添加一个正常的页面链接 ([href^="#"]),只要我在主页 (/) 上它就可以正常工作,但是每当我在不同的整个应用重新加载到主页的 URL。
显然这是一个已知问题 (https://github.com/angular/angular/issues/6595),但我现在需要它来工作,所以我希望有人能教我如何操作。
我不确定它是否有帮助,但这是我的组件的 TS 和 HTML:
import { Component } from '@angular/core';
import { ROUTER_DIRECTIVES } from '@angular/router-deprecated';
@Component({
selector: 'home',
template: require('./home.component.html'),
directives: [ROUTER_DIRECTIVES]
})
export class HomeComponent {
}
<section id="home" class="section section--full-height">
<h2>Title of the home page</h2>
<nav>
<a [routerLink]="['Search']" class="button button--wide">Search</a>
<a [routerLink]="['Search']">Quick try</a>
</nav>
<footer>
<a href="#home-2" class="icon-down icon--below">Heres how it works</a>
</footer>
</section>
<section id="home-2" class="section section--full-height">
<h2>Lorem ipsum dolor</h2>
<img src="http://placehold.it/200x300">
</section>
如您所见,只有当您在主页 (/)。如果在任何其他 URL 上,该链接将重新加载应用程序。
【问题讨论】:
-
您可以发布您正在使用的 url 或您为此编写的 JavaScript 的 sn-p 吗?
-
@AlvaroJoao 不确定它是否会有所帮助,但已经完成
标签: javascript html angular routing