如何强制NavigationByUrl()在Angular 9中导航域根?

问题描述 投票:1回答:1

我在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

或者,如果不可能,我该如何解决这个问题?

angular angular-routing angular-router angular9
1个回答
0
投票

应该起作用

go(element: any) {
  this.router.navigateByUrl('api/download/pdf/' + element.id);
}
© www.soinside.com 2019 - 2024. All rights reserved.