<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Need Help with implementing Link component when customizing image widget in Experience Builder Custom Widgets</title>
    <link>https://community.esri.com/t5/experience-builder-custom-widgets/need-help-with-implementing-link-component-when/m-p/1393501#M247</link>
    <description>&lt;P&gt;&lt;SPAN&gt;I'm working on customizing image component. Currently, when the cursor hovers over image widgets, the link details are revealed at the bottom left/right corner of the browser.&amp;nbsp;I'm trying to implement a mechanism to hide link details from being displayed in the browser's corner upon hover.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Initially, this widget used a &lt;/SPAN&gt;&amp;lt;Link&amp;gt;&lt;SPAN&gt; component to handle navigation, which worked fine. However, I needed to modify its behavior to dynamically construct URLs based on some configuration and then navigate to those URLs without reloading the entire page.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Original Code Snippet:&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;renderResult = (
  &amp;lt;div className='widget-image-container jimu-widget'&amp;gt;
    &amp;lt;Link to={linkTo} target={target} queryObject={queryObject}&amp;gt;
      {imageContent}
    &amp;lt;/Link&amp;gt;
  &amp;lt;/div&amp;gt;
);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Modified Code Snippet:&lt;/STRONG&gt; I replaced the &amp;lt;Link&amp;gt; with a &amp;lt;div&amp;gt; and added an onClick handler to programmatically navigate to URLs. For web addresses, I use window.open(linkTo.value, target); and for other link types, I construct the URL based on some configuration.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;renderResult = (
  &amp;lt;div className='widget-image-container jimu-widget'&amp;gt;
    &amp;lt;div 
      onClick={() =&amp;gt; {
        if (linkTo.linkType === LinkType.WebAddress) {
          window.open(linkTo.value, target);
        } else {
          constructURLWithConfig();
        }
      }}
      style={{ cursor: 'pointer' }}
    &amp;gt;
      {imageContent}
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
);

function constructURLWithConfig() {
  const config = getAppStore().getState().appConfig;
  let [pageId, viewId] = linkTo.value.split(',');

  let pageLabel = config.pages[pageId] ? config.pages[pageId].label : null;
  let viewLabel = config.views[viewId] ? config.views[viewId].label : null;

  pageLabel = pageLabel ? pageLabel.replace(/\s+/g, '-') : pageLabel;
  viewLabel = viewLabel ? viewLabel.replace(/\s+/g, '-') : viewLabel;

  const currentBaseURL = window.location.origin + window.location.pathname;
  const queryString = `?page=${encodeURIComponent(pageLabel)}&amp;amp;views=${encodeURIComponent(viewLabel)}`;

  const finalURL = currentBaseURL + queryString;

  window.open(finalURL, '_self'); // This is supposed to perform the redirect
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Problem:&lt;/STRONG&gt;&amp;nbsp;It causes&amp;nbsp;a full page reload rather than updating just a specific area or behaving like an SPA navigation.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Question:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Is there a way to update the current view without reloading the whole page, similar to how SPA routing works?&lt;/LI&gt;&lt;LI&gt;Or is there a better approach to achieve dynamic URL navigation without causing a full page reload in this context?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Any suggestions or insights into how to address this problem would be greatly appreciated. I'm looking for a solution that allows for link hiding while maintaining SPA-like behavior without full page reloads.&lt;/P&gt;</description>
    <pubDate>Fri, 08 Mar 2024 22:59:11 GMT</pubDate>
    <dc:creator>JohnnySun</dc:creator>
    <dc:date>2024-03-08T22:59:11Z</dc:date>
    <item>
      <title>Need Help with implementing Link component when customizing image widget</title>
      <link>https://community.esri.com/t5/experience-builder-custom-widgets/need-help-with-implementing-link-component-when/m-p/1393501#M247</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I'm working on customizing image component. Currently, when the cursor hovers over image widgets, the link details are revealed at the bottom left/right corner of the browser.&amp;nbsp;I'm trying to implement a mechanism to hide link details from being displayed in the browser's corner upon hover.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Initially, this widget used a &lt;/SPAN&gt;&amp;lt;Link&amp;gt;&lt;SPAN&gt; component to handle navigation, which worked fine. However, I needed to modify its behavior to dynamically construct URLs based on some configuration and then navigate to those URLs without reloading the entire page.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Original Code Snippet:&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;renderResult = (
  &amp;lt;div className='widget-image-container jimu-widget'&amp;gt;
    &amp;lt;Link to={linkTo} target={target} queryObject={queryObject}&amp;gt;
      {imageContent}
    &amp;lt;/Link&amp;gt;
  &amp;lt;/div&amp;gt;
);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Modified Code Snippet:&lt;/STRONG&gt; I replaced the &amp;lt;Link&amp;gt; with a &amp;lt;div&amp;gt; and added an onClick handler to programmatically navigate to URLs. For web addresses, I use window.open(linkTo.value, target); and for other link types, I construct the URL based on some configuration.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;renderResult = (
  &amp;lt;div className='widget-image-container jimu-widget'&amp;gt;
    &amp;lt;div 
      onClick={() =&amp;gt; {
        if (linkTo.linkType === LinkType.WebAddress) {
          window.open(linkTo.value, target);
        } else {
          constructURLWithConfig();
        }
      }}
      style={{ cursor: 'pointer' }}
    &amp;gt;
      {imageContent}
    &amp;lt;/div&amp;gt;
  &amp;lt;/div&amp;gt;
);

function constructURLWithConfig() {
  const config = getAppStore().getState().appConfig;
  let [pageId, viewId] = linkTo.value.split(',');

  let pageLabel = config.pages[pageId] ? config.pages[pageId].label : null;
  let viewLabel = config.views[viewId] ? config.views[viewId].label : null;

  pageLabel = pageLabel ? pageLabel.replace(/\s+/g, '-') : pageLabel;
  viewLabel = viewLabel ? viewLabel.replace(/\s+/g, '-') : viewLabel;

  const currentBaseURL = window.location.origin + window.location.pathname;
  const queryString = `?page=${encodeURIComponent(pageLabel)}&amp;amp;views=${encodeURIComponent(viewLabel)}`;

  const finalURL = currentBaseURL + queryString;

  window.open(finalURL, '_self'); // This is supposed to perform the redirect
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Problem:&lt;/STRONG&gt;&amp;nbsp;It causes&amp;nbsp;a full page reload rather than updating just a specific area or behaving like an SPA navigation.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Question:&lt;/STRONG&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Is there a way to update the current view without reloading the whole page, similar to how SPA routing works?&lt;/LI&gt;&lt;LI&gt;Or is there a better approach to achieve dynamic URL navigation without causing a full page reload in this context?&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Any suggestions or insights into how to address this problem would be greatly appreciated. I'm looking for a solution that allows for link hiding while maintaining SPA-like behavior without full page reloads.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Mar 2024 22:59:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/experience-builder-custom-widgets/need-help-with-implementing-link-component-when/m-p/1393501#M247</guid>
      <dc:creator>JohnnySun</dc:creator>
      <dc:date>2024-03-08T22:59:11Z</dc:date>
    </item>
  </channel>
</rss>

