Can we get community base url without apex?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty{ margin-bottom:0;
}






up vote
4
down vote

favorite












I want to get community base url in my lightning component without apex. Right now I am using the design component to store the value but that is not optimal as I have multiple page references and typing each of them in the community builder is really hard and error prone.










share|improve this question







New contributor




sfdcLynx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.


























    up vote
    4
    down vote

    favorite












    I want to get community base url in my lightning component without apex. Right now I am using the design component to store the value but that is not optimal as I have multiple page references and typing each of them in the community builder is really hard and error prone.










    share|improve this question







    New contributor




    sfdcLynx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






















      up vote
      4
      down vote

      favorite









      up vote
      4
      down vote

      favorite











      I want to get community base url in my lightning component without apex. Right now I am using the design component to store the value but that is not optimal as I have multiple page references and typing each of them in the community builder is really hard and error prone.










      share|improve this question







      New contributor




      sfdcLynx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      I want to get community base url in my lightning component without apex. Right now I am using the design component to store the value but that is not optimal as I have multiple page references and typing each of them in the community builder is really hard and error prone.







      lightning-components community






      share|improve this question







      New contributor




      sfdcLynx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      sfdcLynx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      sfdcLynx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 14 at 16:37









      sfdcLynx

      1006




      1006




      New contributor




      sfdcLynx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      sfdcLynx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      sfdcLynx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          5
          down vote



          accepted










          Yes, you can retrieve the current page url in your JavaScript controller. And set the value of attribute in your component for later use according to your requirement.



          Component



           <aura:attribute name="cbaseURL" type="String"/>


          JS Controller



           var urlString = window.location.href;
          var baseURL = urlString.substring(0, urlString.indexOf("/s"));
          component.set("v.cbaseURL", baseURL);


          Hope this helps.



          EDIT:



          As RedDevil highlighted that using window.location can create issues with Microsoft browsers. I tend to search a bit and find out interesting result. So I'd like to all the readers must go through this stackoverflow link to read about the details and use whatever suits you best.



          However the widely accepted answer says:




          document.location is a synonym for window.location that has been
          deprecated for almost as long as JavaScript has existed. Don't use it.



          location is a structured object, with properties corresponding to the
          parts of the URL. location.href is the whole URL in a single string.
          Assigning a string to either is defined to cause the same kind of
          navigation, so take your pick.



          I consider writing to location.href = something to be marginally
          better as it's slightly more explicit about what it's doing. You
          generally want to avoid just location = something as it looks
          misleadingly like a variable assignment. window.location = something
          is fine though.







          share|improve this answer



















          • 1




            use document.location instead of window.location since this has issues in Microsoft browsers.
            – RedDevil
            Nov 14 at 16:45











          Your Answer








          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "459"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });






          sfdcLynx is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f239372%2fcan-we-get-community-base-url-without-apex%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          5
          down vote



          accepted










          Yes, you can retrieve the current page url in your JavaScript controller. And set the value of attribute in your component for later use according to your requirement.



          Component



           <aura:attribute name="cbaseURL" type="String"/>


          JS Controller



           var urlString = window.location.href;
          var baseURL = urlString.substring(0, urlString.indexOf("/s"));
          component.set("v.cbaseURL", baseURL);


          Hope this helps.



          EDIT:



          As RedDevil highlighted that using window.location can create issues with Microsoft browsers. I tend to search a bit and find out interesting result. So I'd like to all the readers must go through this stackoverflow link to read about the details and use whatever suits you best.



          However the widely accepted answer says:




          document.location is a synonym for window.location that has been
          deprecated for almost as long as JavaScript has existed. Don't use it.



          location is a structured object, with properties corresponding to the
          parts of the URL. location.href is the whole URL in a single string.
          Assigning a string to either is defined to cause the same kind of
          navigation, so take your pick.



          I consider writing to location.href = something to be marginally
          better as it's slightly more explicit about what it's doing. You
          generally want to avoid just location = something as it looks
          misleadingly like a variable assignment. window.location = something
          is fine though.







          share|improve this answer



















          • 1




            use document.location instead of window.location since this has issues in Microsoft browsers.
            – RedDevil
            Nov 14 at 16:45















          up vote
          5
          down vote



          accepted










          Yes, you can retrieve the current page url in your JavaScript controller. And set the value of attribute in your component for later use according to your requirement.



          Component



           <aura:attribute name="cbaseURL" type="String"/>


          JS Controller



           var urlString = window.location.href;
          var baseURL = urlString.substring(0, urlString.indexOf("/s"));
          component.set("v.cbaseURL", baseURL);


          Hope this helps.



          EDIT:



          As RedDevil highlighted that using window.location can create issues with Microsoft browsers. I tend to search a bit and find out interesting result. So I'd like to all the readers must go through this stackoverflow link to read about the details and use whatever suits you best.



          However the widely accepted answer says:




          document.location is a synonym for window.location that has been
          deprecated for almost as long as JavaScript has existed. Don't use it.



          location is a structured object, with properties corresponding to the
          parts of the URL. location.href is the whole URL in a single string.
          Assigning a string to either is defined to cause the same kind of
          navigation, so take your pick.



          I consider writing to location.href = something to be marginally
          better as it's slightly more explicit about what it's doing. You
          generally want to avoid just location = something as it looks
          misleadingly like a variable assignment. window.location = something
          is fine though.







          share|improve this answer



















          • 1




            use document.location instead of window.location since this has issues in Microsoft browsers.
            – RedDevil
            Nov 14 at 16:45













          up vote
          5
          down vote



          accepted







          up vote
          5
          down vote



          accepted






          Yes, you can retrieve the current page url in your JavaScript controller. And set the value of attribute in your component for later use according to your requirement.



          Component



           <aura:attribute name="cbaseURL" type="String"/>


          JS Controller



           var urlString = window.location.href;
          var baseURL = urlString.substring(0, urlString.indexOf("/s"));
          component.set("v.cbaseURL", baseURL);


          Hope this helps.



          EDIT:



          As RedDevil highlighted that using window.location can create issues with Microsoft browsers. I tend to search a bit and find out interesting result. So I'd like to all the readers must go through this stackoverflow link to read about the details and use whatever suits you best.



          However the widely accepted answer says:




          document.location is a synonym for window.location that has been
          deprecated for almost as long as JavaScript has existed. Don't use it.



          location is a structured object, with properties corresponding to the
          parts of the URL. location.href is the whole URL in a single string.
          Assigning a string to either is defined to cause the same kind of
          navigation, so take your pick.



          I consider writing to location.href = something to be marginally
          better as it's slightly more explicit about what it's doing. You
          generally want to avoid just location = something as it looks
          misleadingly like a variable assignment. window.location = something
          is fine though.







          share|improve this answer














          Yes, you can retrieve the current page url in your JavaScript controller. And set the value of attribute in your component for later use according to your requirement.



          Component



           <aura:attribute name="cbaseURL" type="String"/>


          JS Controller



           var urlString = window.location.href;
          var baseURL = urlString.substring(0, urlString.indexOf("/s"));
          component.set("v.cbaseURL", baseURL);


          Hope this helps.



          EDIT:



          As RedDevil highlighted that using window.location can create issues with Microsoft browsers. I tend to search a bit and find out interesting result. So I'd like to all the readers must go through this stackoverflow link to read about the details and use whatever suits you best.



          However the widely accepted answer says:




          document.location is a synonym for window.location that has been
          deprecated for almost as long as JavaScript has existed. Don't use it.



          location is a structured object, with properties corresponding to the
          parts of the URL. location.href is the whole URL in a single string.
          Assigning a string to either is defined to cause the same kind of
          navigation, so take your pick.



          I consider writing to location.href = something to be marginally
          better as it's slightly more explicit about what it's doing. You
          generally want to avoid just location = something as it looks
          misleadingly like a variable assignment. window.location = something
          is fine though.








          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 14 at 16:59









          sfdcLynx

          1006




          1006










          answered Nov 14 at 16:43









          LetMeCodeYou

          51838




          51838








          • 1




            use document.location instead of window.location since this has issues in Microsoft browsers.
            – RedDevil
            Nov 14 at 16:45














          • 1




            use document.location instead of window.location since this has issues in Microsoft browsers.
            – RedDevil
            Nov 14 at 16:45








          1




          1




          use document.location instead of window.location since this has issues in Microsoft browsers.
          – RedDevil
          Nov 14 at 16:45




          use document.location instead of window.location since this has issues in Microsoft browsers.
          – RedDevil
          Nov 14 at 16:45










          sfdcLynx is a new contributor. Be nice, and check out our Code of Conduct.










           

          draft saved


          draft discarded


















          sfdcLynx is a new contributor. Be nice, and check out our Code of Conduct.













          sfdcLynx is a new contributor. Be nice, and check out our Code of Conduct.












          sfdcLynx is a new contributor. Be nice, and check out our Code of Conduct.















           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f239372%2fcan-we-get-community-base-url-without-apex%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Plaza Victoria

          Puebla de Zaragoza

          Musa