![](/img/trans.png)
[英]Finding or creating the url for a new Lightning Web Component/ Sales Force
[英]Call lightning Web Component from URL and capture parameter from URL
我想通過單擊體驗雲中的 URL 將用戶從一個 LWC 重定向到另一個。 基本上,在我的第一個 LWC 上,我顯示從 Apex 檢索到的記錄列表,然后當單擊任何行時,我想傳遞該行的 recordId 並重定向到第二個 LWC,它將顯示記錄詳細信息頁面。 我怎樣才能做到這一點?
您是否有社區...抱歉,該目標 LWC 的體驗生成器頁面已刪除?
您可以使用NavigationMixin ,盡管文檔說社區不支持state
屬性。
在源端嘗試類似
/* Assumes the link/button clicked looks like
<button data-id={acc.Id} onclick={handleClick}>Get details</button>
*/
handleClick(event){
if(event.currentTarget.dataset.id){
this[NavigationMixin.Navigate]({
type: 'comm__namedPage',
attributes: {
name: 'MyTargetCommunityPage__c'
},
state: {
id: event.currentTarget.dataset.id
}
});
}
}
然后在目標頁面的 LWC 上,它應該可以作為
connectedCallback() {
if(window.location.href){
try{
let url = new URL(window.location.href);
var id = url.searchParams.get('id');
if(id){
this.myId = id;
}
} catch(e){
if(console){
console.log(JSON.stringify(e));
}
}
}
}
如果導航給您帶來困難,您可以放棄它並直接使用window.open('/pagename?id=123', _self);
或者其他的東西。 你有一套核心 Salesforce 規則,1 套社區規則,這有點煩人。
(如果您有命名空間 - 您可能需要在myns__id
中使用state
而不是id
)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.