简体   繁体   中英

Reset subEntityId as empty once desired task is executed in MS Teams Tabs

We have enabled deep linking in Microsoft Teams Tabs. We are generating link to the custom tabs with subEntityId as mentioned in Microsoft docs

https://teams.microsoft.com/l/entity/<appId>/<entityId>?webUrl=<entityWebUrl>&label=<entityLabel>&context=<context>

In home page, we are using Ms Teams Js SDK and calling getContext() for retrieving the subEntityId passed in the URL.

We used the following code for navigating to different page based on subEntityId

microsoftTeams.initialize();
microsoftTeams.getContext(function (context) {
    console.log(context);
    let currentUrl = window.location.href;
    let isAdmin = false;
    if(currentUrl.indexOf('admin') > 0){
        isAdmin = true;
    }
   let subEntityId = context.subEntityId;
    let redirectUrl = "";
    if(subEntityId == "all-tasks")
    {
        redirectUrl = isAdmin ? 
        window.location.origin + "/admin/task/all-tasks" :
        window.location.origin + "/member/task/all-tasks";
    }
     microsoftTeams.setContext
     if(redirectUrl != ""){
        window.location.assign(redirectUrl);
     }
});

but when we are navigating back to home page using navigation bar (not by using any back button) it is automatically redirecting back. The subEntityId is not resetting and on home page load it is picking the id and navigating again.

Please help, is there any possible way to reset or set the subEntityId as empty.

Thank you.

Can you try below code to update subEntityId value after redircting.

microsoftTeams.settings.setSettings({
                    subEntityId: "Reset value here",                        
                });

There appears to be no way to change the context, or otherwise record that the subEntityId has already been followed once, using the Teams client SDK

My solution was to add a hash or url parameter to the tab's contentURL (during tab configuration).

microsoftTeams.settings.setSettings({
    contentUrl: https://my_tab_url#follow_deep_link,
})

Then the subEntityId is only used when this hash is present. Subsequent navigation within the tab removes the #follow_deep_link and subEntityId is not used.

if (window.location.hash === '#follow_deep_link') {
  microsoftTeams.getContext(function (context) {
    //handle subEntityId
  })
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM