【发布时间】:2020-02-03 19:00:37
【问题描述】:
我是 Angular 8 的新手。 在我的 localhost:4200 我有一个链接:
点击这里下载我的计划 (PDF)
我点击链接,我的网址是http://localhost:4200/#/LabViewerPDF,但它仍然显示:
点击这里下载我的计划 (PDF) 实验室查看器有效!
我期待它显示:
实验室查看器有效!
但它仍然显示,但 url 是 http://localhost:4200/#/LabViewerPDF: 单击此处下载我的计划 (PDF) 实验室查看器有效!
这是我的 app.component.html
<a (click)="selectLab()">Click here to download my Plan (PDF)</a>
<router-outlet></router-outlet>
这是我的 app.component.ts 代码:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css'],
})
export class AppComponent {
title = 'test1';
selectLab() {
let url = `/#/LabViewerPDF`;
window.open(url);
}
}
这是我的 app-routing.module.ts:
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { LabViewerComponent } from './lab-viewer/lab-viewer.component';
const routes: Routes = [
{ path: 'LabViewerPDF', component: LabViewerComponent}
];
@NgModule({
imports: [RouterModule.forRoot(routes, {useHash: true})],
exports: [RouterModule]
})
export class AppRoutingModule { }
这是我的 lab-view.component.html:
<p>lab-viewer works!</p>
为什么我点击链接后显示原来的值和新的值:
点击这里下载我的计划 (PDF) 实验室查看器有效!
我希望点击链接后只显示: 实验室查看器有效!
【问题讨论】:
-
请分享您的路由配置,如果您没有明确设置,默认情况下 Angular 的路由策略不是基于哈希的。
标签: angular typescript