Angular 7 Router - Navigate without adding to the history

Multi tool use
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

add a comment |
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

add a comment |
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

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

javascript

asked Jan 3 at 9:06
Alex YorkAlex York
103
103
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
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 usingreplaceUrl
instead ofskipLocationChange
. It's also an option ofNavigationExtras
.
– 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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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 usingreplaceUrl
instead ofskipLocationChange
. It's also an option ofNavigationExtras
.
– 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
add a comment |
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
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 usingreplaceUrl
instead ofskipLocationChange
. It's also an option ofNavigationExtras
.
– 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
add a comment |
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
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
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 usingreplaceUrl
instead ofskipLocationChange
. It's also an option ofNavigationExtras
.
– 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
add a comment |
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 usingreplaceUrl
instead ofskipLocationChange
. It's also an option ofNavigationExtras
.
– 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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