Angular 新标签页导航
Angular new tab navigation
我创建了两个组件和一个由它们使用的服务。我希望默认呈现一个组件,并从该组件内呈现一个 link,它将在不更改 url(无路由)的情况下在新选项卡上打开另一个组件。
one.component.html
This is the default component and contains the link to open another component in a seperate tab but with same url.
<a (click)="openNewTab()"></a>
one.component.ts
// xyz code
window.open('/', '_blank').focus()
two.component.html
<ng-template #two>
This should be opened in a seperate tab
</ng-template>
您必须将第二个组件的完整 URL 路径传递到您的
window.open('/', '_blank').focus()
方法。
- 目前您只传递单个
/
这意味着它不会重定向到您的第二个组件的特定路径。
- 尝试像这样更改 URL,
window.open('localhost:4000/secondURL', '_blank').focus()
其中 secondURL
是第二个组件的 URL。
我创建了两个组件和一个由它们使用的服务。我希望默认呈现一个组件,并从该组件内呈现一个 link,它将在不更改 url(无路由)的情况下在新选项卡上打开另一个组件。
one.component.html
This is the default component and contains the link to open another component in a seperate tab but with same url.
<a (click)="openNewTab()"></a>
one.component.ts
// xyz code
window.open('/', '_blank').focus()
two.component.html
<ng-template #two>
This should be opened in a seperate tab
</ng-template>
您必须将第二个组件的完整 URL 路径传递到您的
window.open('/', '_blank').focus()
方法。
- 目前您只传递单个
/
这意味着它不会重定向到您的第二个组件的特定路径。 - 尝试像这样更改 URL,
window.open('localhost:4000/secondURL', '_blank').focus()
其中 secondURL
是第二个组件的 URL。