Angular 7 Router - Navigate without adding to the history

Multi tool use
Multi tool use












0















I need your help right now!



I have Angular Router and I want to navigate to another url without adding it to the browser history, because back button will return user back to the url again and again.



this.router.navigateByUrl(`${pathWithoutFragment}#${newFragment}`);


My code here.
Can I do it with only Angular instruments or I need to use History API ?
Thank you!










share|improve this question



























    0















    I need your help right now!



    I have Angular Router and I want to navigate to another url without adding it to the browser history, because back button will return user back to the url again and again.



    this.router.navigateByUrl(`${pathWithoutFragment}#${newFragment}`);


    My code here.
    Can I do it with only Angular instruments or I need to use History API ?
    Thank you!










    share|improve this question

























      0












      0








      0








      I need your help right now!



      I have Angular Router and I want to navigate to another url without adding it to the browser history, because back button will return user back to the url again and again.



      this.router.navigateByUrl(`${pathWithoutFragment}#${newFragment}`);


      My code here.
      Can I do it with only Angular instruments or I need to use History API ?
      Thank you!










      share|improve this question














      I need your help right now!



      I have Angular Router and I want to navigate to another url without adding it to the browser history, because back button will return user back to the url again and again.



      this.router.navigateByUrl(`${pathWithoutFragment}#${newFragment}`);


      My code here.
      Can I do it with only Angular instruments or I need to use History API ?
      Thank you!







      javascript angular router history






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 3 at 9:06









      Alex YorkAlex York

      103




      103
























          1 Answer
          1






          active

          oldest

          votes


















          0














          As @IngoBürk Mentioned in the comment you can achieve the same result without using skiplocationChange



           this.router.replaceUrl('path')


          skipLocationChange




          Navigates without pushing a new state into history.




          this.router.navigateByUrl([`${pathWithoutFragment}#${newFragment}`], { skipLocationChange: true });


          Ref:https://angular.io/api/router/NavigationExtras#skipLocationChange






          share|improve this answer





















          • 1





            I think replaceUrl is the correct answer here. skipLocationChange will not update the URL either, and it doesn't sound like that's what OP wants.

            – Ingo Bürk
            Jan 3 at 9:43











          • @IngoBürk Thanks. I have edited my post.

            – Chellappan
            Jan 3 at 10:02











          • I don't see what your edit has to do with my comment? I meant using replaceUrl instead of skipLocationChange. It's also an option of NavigationExtras.

            – Ingo Bürk
            Jan 3 at 10:09








          • 1





            No, it replaces the state. Which means the URL will update in the address bar, but there's no new event on the stack, so clicking the back button leads to the same previous page as without that navigation. If you use skipLocationChange, you have that effect as well, but the URL won't update in the address bar.

            – Ingo Bürk
            Jan 3 at 10:13











          • Your new edit is still wrong. Again, you need to use replaceUrl. Now you just edited to using no flag at all, which is a normal navigation. I'm going to stop trying to explain this now, I think it's been more than clear...

            – Ingo Bürk
            Jan 3 at 10:23











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          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',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          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
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54019149%2fangular-7-router-navigate-without-adding-to-the-history%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









          0














          As @IngoBürk Mentioned in the comment you can achieve the same result without using skiplocationChange



           this.router.replaceUrl('path')


          skipLocationChange




          Navigates without pushing a new state into history.




          this.router.navigateByUrl([`${pathWithoutFragment}#${newFragment}`], { skipLocationChange: true });


          Ref:https://angular.io/api/router/NavigationExtras#skipLocationChange






          share|improve this answer





















          • 1





            I think replaceUrl is the correct answer here. skipLocationChange will not update the URL either, and it doesn't sound like that's what OP wants.

            – Ingo Bürk
            Jan 3 at 9:43











          • @IngoBürk Thanks. I have edited my post.

            – Chellappan
            Jan 3 at 10:02











          • I don't see what your edit has to do with my comment? I meant using replaceUrl instead of skipLocationChange. It's also an option of NavigationExtras.

            – Ingo Bürk
            Jan 3 at 10:09








          • 1





            No, it replaces the state. Which means the URL will update in the address bar, but there's no new event on the stack, so clicking the back button leads to the same previous page as without that navigation. If you use skipLocationChange, you have that effect as well, but the URL won't update in the address bar.

            – Ingo Bürk
            Jan 3 at 10:13











          • Your new edit is still wrong. Again, you need to use replaceUrl. Now you just edited to using no flag at all, which is a normal navigation. I'm going to stop trying to explain this now, I think it's been more than clear...

            – Ingo Bürk
            Jan 3 at 10:23
















          0














          As @IngoBürk Mentioned in the comment you can achieve the same result without using skiplocationChange



           this.router.replaceUrl('path')


          skipLocationChange




          Navigates without pushing a new state into history.




          this.router.navigateByUrl([`${pathWithoutFragment}#${newFragment}`], { skipLocationChange: true });


          Ref:https://angular.io/api/router/NavigationExtras#skipLocationChange






          share|improve this answer





















          • 1





            I think replaceUrl is the correct answer here. skipLocationChange will not update the URL either, and it doesn't sound like that's what OP wants.

            – Ingo Bürk
            Jan 3 at 9:43











          • @IngoBürk Thanks. I have edited my post.

            – Chellappan
            Jan 3 at 10:02











          • I don't see what your edit has to do with my comment? I meant using replaceUrl instead of skipLocationChange. It's also an option of NavigationExtras.

            – Ingo Bürk
            Jan 3 at 10:09








          • 1





            No, it replaces the state. Which means the URL will update in the address bar, but there's no new event on the stack, so clicking the back button leads to the same previous page as without that navigation. If you use skipLocationChange, you have that effect as well, but the URL won't update in the address bar.

            – Ingo Bürk
            Jan 3 at 10:13











          • Your new edit is still wrong. Again, you need to use replaceUrl. Now you just edited to using no flag at all, which is a normal navigation. I'm going to stop trying to explain this now, I think it's been more than clear...

            – Ingo Bürk
            Jan 3 at 10:23














          0












          0








          0







          As @IngoBürk Mentioned in the comment you can achieve the same result without using skiplocationChange



           this.router.replaceUrl('path')


          skipLocationChange




          Navigates without pushing a new state into history.




          this.router.navigateByUrl([`${pathWithoutFragment}#${newFragment}`], { skipLocationChange: true });


          Ref:https://angular.io/api/router/NavigationExtras#skipLocationChange






          share|improve this answer















          As @IngoBürk Mentioned in the comment you can achieve the same result without using skiplocationChange



           this.router.replaceUrl('path')


          skipLocationChange




          Navigates without pushing a new state into history.




          this.router.navigateByUrl([`${pathWithoutFragment}#${newFragment}`], { skipLocationChange: true });


          Ref:https://angular.io/api/router/NavigationExtras#skipLocationChange







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Jan 3 at 10:27

























          answered Jan 3 at 9:10









          ChellappanChellappan

          5,7612421




          5,7612421








          • 1





            I think replaceUrl is the correct answer here. skipLocationChange will not update the URL either, and it doesn't sound like that's what OP wants.

            – Ingo Bürk
            Jan 3 at 9:43











          • @IngoBürk Thanks. I have edited my post.

            – Chellappan
            Jan 3 at 10:02











          • I don't see what your edit has to do with my comment? I meant using replaceUrl instead of skipLocationChange. It's also an option of NavigationExtras.

            – Ingo Bürk
            Jan 3 at 10:09








          • 1





            No, it replaces the state. Which means the URL will update in the address bar, but there's no new event on the stack, so clicking the back button leads to the same previous page as without that navigation. If you use skipLocationChange, you have that effect as well, but the URL won't update in the address bar.

            – Ingo Bürk
            Jan 3 at 10:13











          • Your new edit is still wrong. Again, you need to use replaceUrl. Now you just edited to using no flag at all, which is a normal navigation. I'm going to stop trying to explain this now, I think it's been more than clear...

            – Ingo Bürk
            Jan 3 at 10:23














          • 1





            I think replaceUrl is the correct answer here. skipLocationChange will not update the URL either, and it doesn't sound like that's what OP wants.

            – Ingo Bürk
            Jan 3 at 9:43











          • @IngoBürk Thanks. I have edited my post.

            – Chellappan
            Jan 3 at 10:02











          • I don't see what your edit has to do with my comment? I meant using replaceUrl instead of skipLocationChange. It's also an option of NavigationExtras.

            – Ingo Bürk
            Jan 3 at 10:09








          • 1





            No, it replaces the state. Which means the URL will update in the address bar, but there's no new event on the stack, so clicking the back button leads to the same previous page as without that navigation. If you use skipLocationChange, you have that effect as well, but the URL won't update in the address bar.

            – Ingo Bürk
            Jan 3 at 10:13











          • Your new edit is still wrong. Again, you need to use replaceUrl. Now you just edited to using no flag at all, which is a normal navigation. I'm going to stop trying to explain this now, I think it's been more than clear...

            – Ingo Bürk
            Jan 3 at 10:23








          1




          1





          I think replaceUrl is the correct answer here. skipLocationChange will not update the URL either, and it doesn't sound like that's what OP wants.

          – Ingo Bürk
          Jan 3 at 9:43





          I think replaceUrl is the correct answer here. skipLocationChange will not update the URL either, and it doesn't sound like that's what OP wants.

          – Ingo Bürk
          Jan 3 at 9:43













          @IngoBürk Thanks. I have edited my post.

          – Chellappan
          Jan 3 at 10:02





          @IngoBürk Thanks. I have edited my post.

          – Chellappan
          Jan 3 at 10:02













          I don't see what your edit has to do with my comment? I meant using replaceUrl instead of skipLocationChange. It's also an option of NavigationExtras.

          – Ingo Bürk
          Jan 3 at 10:09







          I don't see what your edit has to do with my comment? I meant using replaceUrl instead of skipLocationChange. It's also an option of NavigationExtras.

          – Ingo Bürk
          Jan 3 at 10:09






          1




          1





          No, it replaces the state. Which means the URL will update in the address bar, but there's no new event on the stack, so clicking the back button leads to the same previous page as without that navigation. If you use skipLocationChange, you have that effect as well, but the URL won't update in the address bar.

          – Ingo Bürk
          Jan 3 at 10:13





          No, it replaces the state. Which means the URL will update in the address bar, but there's no new event on the stack, so clicking the back button leads to the same previous page as without that navigation. If you use skipLocationChange, you have that effect as well, but the URL won't update in the address bar.

          – Ingo Bürk
          Jan 3 at 10:13













          Your new edit is still wrong. Again, you need to use replaceUrl. Now you just edited to using no flag at all, which is a normal navigation. I'm going to stop trying to explain this now, I think it's been more than clear...

          – Ingo Bürk
          Jan 3 at 10:23





          Your new edit is still wrong. Again, you need to use replaceUrl. Now you just edited to using no flag at all, which is a normal navigation. I'm going to stop trying to explain this now, I think it's been more than clear...

          – Ingo Bürk
          Jan 3 at 10:23




















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54019149%2fangular-7-router-navigate-without-adding-to-the-history%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







          eGAOiC6ZZ7aQXAgnF1jhG9YU,N83RtlpYiLaAFSg31Xk9Z,cbvVuLn,lyI0qz5zpnP4iAt5lph RffzCw,F
          5Wc5FM2g2 4hP9UdqeIB,9YYl elDeq u2SW,KLzD6Lo3vunz2i1 1 Pr6HYOFWawN1ZFg,IifpbLa

          Popular posts from this blog

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas