我在http://project.test/admin
上运行的Angular项目。我尝试导航用户以从http://project.test/api/download/pdf/1
开始下载,但是navgateByUrl()
总是以/admin
开始链接。
这是我的代码:
import { Component } from '@angular/core';
import { Router } from '@angular/router';
import { InjectorInstance } from 'src/app/app.module';
@Component({
selector: 'app-my',
templateUrl: './my.component.html',
styleUrls: ['./my.component.scss']
})
export class MyComponent {
token = localStorage.getItem('token') || '';
private router: Router = InjectorInstance.get<Router>(Router);
go(element: any) {
this.router.navigateByUrl('/api/download/pdf/' + element.id);
}
}
如何强制router.navigateByUrl()
浏览此URL:http://project.test/api/download/pdf/1
?
或者,如果不可能,我该如何解决这个问题?
应该起作用
go(element: any) {
this.router.navigateByUrl('api/download/pdf/' + element.id);
}