Lightning Experience の openTab()
新しいワークスペースタブを開きます。タブがすでに開いている場合、タブがフォーカスされます。このメソッドは、Lightning コンソールアプリケーションでのみ機能します。
引数
| 名前 | 型 | 説明 |
|---|---|---|
| pageReference | object | 開く pageReference を指定します。pageReference は省略可能です。 |
| recordId | ID | 開くレコードを指定します。recordId は省略可能です。 |
| url | URL |
新しいワークスペースタブのコンテンツを表す URL。url は省略可能です。 URL は、相対 URL または絶対 URL になります。サードパーティドメインを使用するには、サイトを CSP 信頼済みサイトとして追加します。 |
| focus | boolean | 新しいタブにフォーカスするかどうかを指定します。すぐにタブを表示するには、focus を true に設定します。バックグラウンドでタブを開くには、focus を false に設定します。 |
| overrideNavRules | boolean | 省略可能。開いているタブに既存のナビゲーションルールが適用されるかどうかを指定します。この引数は、ナビゲーションルールが設定されていないレコードや、レコードを指し示していない URL には影響しません。 |
サンプルコード
このコンポーネントにはボタンがあり、押すと、タブが開きます。
コンポーネントコード:
1<aura:component implements="flexipage:availableForAllPageTypes" access="global">
2 <lightning:workspaceAPI aura:id="workspace"/>
3 <lightning:button label="Open Tab" onclick="{!c.openTab}"/>
4</aura:component>コントローラコード (pageReference):
1({
2openTab: function(component, event, helper) {
3 var workspaceAPI = component.find("workspace");
4 workspaceAPI.openTab({
5 pageReference: {
6 "type": "standard__recordPage",
7 "attributes": {
8 "recordId":"500xx000000Ykt2AAC",
9 "actionName":"view"
10 },
11 "state": {}
12 },
13 focus: true
14 }).then(function(response) {
15 workspaceAPI.getTabInfo({
16 tabId: response
17 }).then(function(tabInfo) {
18 console.log("The recordId for this tab is: " + tabInfo.recordId);
19 });
20 }).catch(function(error) {
21 console.log(error);
22 });
23 }
24)}コントローラコード (recordId):
1({
2 openTab : function(component, event, helper) {
3 var workspaceAPI = component.find("workspace");
4 workspaceAPI.openTab({
5 recordId: '001xx000003DIkeAAG',
6 focus: true
7 }).then(function(response) {
8 workspaceAPI.getTabInfo({
9 tabId: response
10 }).then(function(tabInfo) {
11 console.log("The url for this tab is: " + tabInfo.url);
12 });
13 })
14 .catch(function(error) {
15 console.log(error);
16 });
17 }
18})コントローラコード (url):
1({
2 openTab : function(component, event, helper) {
3 var workspaceAPI = component.find("workspace");
4 workspaceAPI.openTab({
5 url: '/lightning/r/Account/001xx000003DI05AAG/view',
6 focus: true
7 }).then(function(response) {
8 workspaceAPI.getTabInfo({
9 tabId: response
10 }).then(function(tabInfo) {
11 console.log("The recordId for this tab is: " + tabInfo.recordId);
12 });
13 }).catch(function(error) {
14 console.log(error);
15 });
16 }
17})応答
このメソッドは、成功時に新しいタブの tabId に解決される Promise を返します。