this.router.navigate() doesn't navigate to the URLHow to pass url arguments (query string) to a HTTP request on Angular?How to get query params from url in Angular 2?Angular2 routing and saving/restoring navigation stateRouting child to parent is not working when navigates in AngularAcquireToken Observable errors before returning tokenGet angular router route configuration for target in router event handlingUsing Injector to retrieve services breaks SSR, using route resolvers and inherited componentsHow can I prevent the Angular 6 Custom-Reuse-Strategy from caching a 403 forbidden page?How to create a custom pipe that paginates data in Angular?Handling Components Inside another Component in Angular
How would a sea turtle end up on its back?
Boss furious on bad appraisal
How can select a specific triangle in my Delaunay mesh?
How did Einstein know the speed of light was constant?
In the Seventh Seal why does Death let the chess game happen?
Why no parachutes in the Orion AA2 abort test?
Taking advantage when the HR forgets to communicate the rules
Machine Learning Golf: Multiplication
Should I cheat if the majority does it?
Is there a standard definition of the "stall" phenomena?
How did שְׁלֹמֹה (shlomo) become Solomon?
Would the Life cleric's Disciple of Life feature supercharge the Regenerate spell?
Do I need to be legally qualified to install a Hive smart thermostat?
What is the fundamental difference between catching whales and hunting other animals?
What happens if the limit of 4 billion files was exceeded in an ext4 partition?
Sleepy tired vs physically tired
How can I effectively map a multi-level dungeon?
Lie bracket of vector fields in Penrose's abstract index notation
How do I iterate equal values with the standard library?
Why do Klingons use cloaking devices?
Sci-fi book (no magic, hyperspace jumps, blind protagonist)
Can you take the Dodge action while prone?
Speeding up thousands of string parses
Why do most airliners have underwing engines, while business jets have rear-mounted engines?
this.router.navigate() doesn't navigate to the URL
How to pass url arguments (query string) to a HTTP request on Angular?How to get query params from url in Angular 2?Angular2 routing and saving/restoring navigation stateRouting child to parent is not working when navigates in AngularAcquireToken Observable errors before returning tokenGet angular router route configuration for target in router event handlingUsing Injector to retrieve services breaks SSR, using route resolvers and inherited componentsHow can I prevent the Angular 6 Custom-Reuse-Strategy from caching a 403 forbidden page?How to create a custom pipe that paginates data in Angular?Handling Components Inside another Component in Angular
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a pagination demo application in Angular. I am expecting to be able to navigate to a URL like http://localhost:4200/page/:number
. The URL appears to be changing in the browser's URL address bar but I have to press Enter key on the browser's URL address bar in order to actually navigate to the URL and have the data change on the HTML table.
Stackblitz here: https://stackblitz.com/edit/angular-225jrs (HttpErrorResponse
is not part of the question, but I don't know how to fix that in Stackblitz). Here is my code:
page.component.html:
<span *ngFor="let x of fakeArray; let index = index">
<button type="button" class="btn btn-primary" (click)="goToPage(index)"> index + 1 </button>
</span>
<br><br>
<table class="table">
<thead>
<tr>
<th>Alue-ID</th>
<th>Kunta</th>
<th>Lääni</th>
<th>Maakunta</th>
<th>Seutukunta</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let municipality of municipalities">
<td> municipality.alue_id </td>
<td> municipality.kunta </td>
<td> municipality.laani </td>
<td> municipality.maakunta </td>
<td> municipality.seutukunta </td>
</tr>
</tbody>
</table>
<span *ngFor="let x of fakeArray; let index = index">
<button type="button" class="btn btn-primary" (click)="goToPage(index)"> index + 1 </button>
</span>
<br><br>
page.component.ts:
import Component, OnInit from '@angular/core';
import MunicipalitiesService from '../municipalities.service';
import municipality from '../municipality.interface';
import ActivatedRoute, Router from '@angular/router';
@Component(
selector: 'app-page',
templateUrl: './page.component.html',
styleUrls: ['./page.component.css']
)
export class PageComponent implements OnInit
municipalities: municipality[] = [];
pagenumber: number;
fakeArray: any;
constructor(
private service: MunicipalitiesService,
private route: ActivatedRoute,
private router: Router)
ngOnInit()
this.route.params.subscribe(params =>
this.pagenumber = +params.number;
)
this.service.getOneHundredRecords(this.pagenumber).then((data: municipality[]) =>
this.municipalities = data;
);
this.service.getPageCount().then((pageCount: number) =>
this.fakeArray = new Array(pageCount);
)
goToPage = (index: number) =>
this.router.navigate([`/page/$index`]);
municipalities.service.ts:
import Injectable from '@angular/core';
import HttpClient from '@angular/common/http';
import municipality from './municipality.interface';
@Injectable()
export class MunicipalitiesService
constructor(private http: HttpClient)
getOneHundredRecords = (page: number) =>
return new Promise((resolve, reject) =>
this.http.get("/assets/data.json").subscribe((data: municipality[]) =>
let municipalities = data;
let index = 0;
let toBeReturned: municipality[] = [];
for (let municipality of municipalities)
if (index >= (page * 100) && index < (page + 1) * 100)
toBeReturned.push(municipality);
index++;
resolve(toBeReturned)
)
)
getPageCount = () =>
return new Promise((resolve, reject) =>
this.http.get("/assets/data.json").subscribe((data: municipality[]) =>
let municipalities = data;
let index = 0;
for (let municipality of municipalities)
index++;
let pageCount = Math.ceil(index / 100);
resolve(pageCount)
)
)
angular typescript
add a comment |
I have a pagination demo application in Angular. I am expecting to be able to navigate to a URL like http://localhost:4200/page/:number
. The URL appears to be changing in the browser's URL address bar but I have to press Enter key on the browser's URL address bar in order to actually navigate to the URL and have the data change on the HTML table.
Stackblitz here: https://stackblitz.com/edit/angular-225jrs (HttpErrorResponse
is not part of the question, but I don't know how to fix that in Stackblitz). Here is my code:
page.component.html:
<span *ngFor="let x of fakeArray; let index = index">
<button type="button" class="btn btn-primary" (click)="goToPage(index)"> index + 1 </button>
</span>
<br><br>
<table class="table">
<thead>
<tr>
<th>Alue-ID</th>
<th>Kunta</th>
<th>Lääni</th>
<th>Maakunta</th>
<th>Seutukunta</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let municipality of municipalities">
<td> municipality.alue_id </td>
<td> municipality.kunta </td>
<td> municipality.laani </td>
<td> municipality.maakunta </td>
<td> municipality.seutukunta </td>
</tr>
</tbody>
</table>
<span *ngFor="let x of fakeArray; let index = index">
<button type="button" class="btn btn-primary" (click)="goToPage(index)"> index + 1 </button>
</span>
<br><br>
page.component.ts:
import Component, OnInit from '@angular/core';
import MunicipalitiesService from '../municipalities.service';
import municipality from '../municipality.interface';
import ActivatedRoute, Router from '@angular/router';
@Component(
selector: 'app-page',
templateUrl: './page.component.html',
styleUrls: ['./page.component.css']
)
export class PageComponent implements OnInit
municipalities: municipality[] = [];
pagenumber: number;
fakeArray: any;
constructor(
private service: MunicipalitiesService,
private route: ActivatedRoute,
private router: Router)
ngOnInit()
this.route.params.subscribe(params =>
this.pagenumber = +params.number;
)
this.service.getOneHundredRecords(this.pagenumber).then((data: municipality[]) =>
this.municipalities = data;
);
this.service.getPageCount().then((pageCount: number) =>
this.fakeArray = new Array(pageCount);
)
goToPage = (index: number) =>
this.router.navigate([`/page/$index`]);
municipalities.service.ts:
import Injectable from '@angular/core';
import HttpClient from '@angular/common/http';
import municipality from './municipality.interface';
@Injectable()
export class MunicipalitiesService
constructor(private http: HttpClient)
getOneHundredRecords = (page: number) =>
return new Promise((resolve, reject) =>
this.http.get("/assets/data.json").subscribe((data: municipality[]) =>
let municipalities = data;
let index = 0;
let toBeReturned: municipality[] = [];
for (let municipality of municipalities)
if (index >= (page * 100) && index < (page + 1) * 100)
toBeReturned.push(municipality);
index++;
resolve(toBeReturned)
)
)
getPageCount = () =>
return new Promise((resolve, reject) =>
this.http.get("/assets/data.json").subscribe((data: municipality[]) =>
let municipalities = data;
let index = 0;
for (let municipality of municipalities)
index++;
let pageCount = Math.ceil(index / 100);
resolve(pageCount)
)
)
angular typescript
1
Technically you are still in the same route to the same component, thus it doesn't reload. You can force the reload by doing this:this.router.navigate([
/page/$index]).then(() => window.location.reload());
however i'd advise doing this because it basically removed all your states. So instead of doingnavigate
it is better if you grab your new set data viagoToPage()
method.
– penleychan
Mar 25 at 20:03
add a comment |
I have a pagination demo application in Angular. I am expecting to be able to navigate to a URL like http://localhost:4200/page/:number
. The URL appears to be changing in the browser's URL address bar but I have to press Enter key on the browser's URL address bar in order to actually navigate to the URL and have the data change on the HTML table.
Stackblitz here: https://stackblitz.com/edit/angular-225jrs (HttpErrorResponse
is not part of the question, but I don't know how to fix that in Stackblitz). Here is my code:
page.component.html:
<span *ngFor="let x of fakeArray; let index = index">
<button type="button" class="btn btn-primary" (click)="goToPage(index)"> index + 1 </button>
</span>
<br><br>
<table class="table">
<thead>
<tr>
<th>Alue-ID</th>
<th>Kunta</th>
<th>Lääni</th>
<th>Maakunta</th>
<th>Seutukunta</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let municipality of municipalities">
<td> municipality.alue_id </td>
<td> municipality.kunta </td>
<td> municipality.laani </td>
<td> municipality.maakunta </td>
<td> municipality.seutukunta </td>
</tr>
</tbody>
</table>
<span *ngFor="let x of fakeArray; let index = index">
<button type="button" class="btn btn-primary" (click)="goToPage(index)"> index + 1 </button>
</span>
<br><br>
page.component.ts:
import Component, OnInit from '@angular/core';
import MunicipalitiesService from '../municipalities.service';
import municipality from '../municipality.interface';
import ActivatedRoute, Router from '@angular/router';
@Component(
selector: 'app-page',
templateUrl: './page.component.html',
styleUrls: ['./page.component.css']
)
export class PageComponent implements OnInit
municipalities: municipality[] = [];
pagenumber: number;
fakeArray: any;
constructor(
private service: MunicipalitiesService,
private route: ActivatedRoute,
private router: Router)
ngOnInit()
this.route.params.subscribe(params =>
this.pagenumber = +params.number;
)
this.service.getOneHundredRecords(this.pagenumber).then((data: municipality[]) =>
this.municipalities = data;
);
this.service.getPageCount().then((pageCount: number) =>
this.fakeArray = new Array(pageCount);
)
goToPage = (index: number) =>
this.router.navigate([`/page/$index`]);
municipalities.service.ts:
import Injectable from '@angular/core';
import HttpClient from '@angular/common/http';
import municipality from './municipality.interface';
@Injectable()
export class MunicipalitiesService
constructor(private http: HttpClient)
getOneHundredRecords = (page: number) =>
return new Promise((resolve, reject) =>
this.http.get("/assets/data.json").subscribe((data: municipality[]) =>
let municipalities = data;
let index = 0;
let toBeReturned: municipality[] = [];
for (let municipality of municipalities)
if (index >= (page * 100) && index < (page + 1) * 100)
toBeReturned.push(municipality);
index++;
resolve(toBeReturned)
)
)
getPageCount = () =>
return new Promise((resolve, reject) =>
this.http.get("/assets/data.json").subscribe((data: municipality[]) =>
let municipalities = data;
let index = 0;
for (let municipality of municipalities)
index++;
let pageCount = Math.ceil(index / 100);
resolve(pageCount)
)
)
angular typescript
I have a pagination demo application in Angular. I am expecting to be able to navigate to a URL like http://localhost:4200/page/:number
. The URL appears to be changing in the browser's URL address bar but I have to press Enter key on the browser's URL address bar in order to actually navigate to the URL and have the data change on the HTML table.
Stackblitz here: https://stackblitz.com/edit/angular-225jrs (HttpErrorResponse
is not part of the question, but I don't know how to fix that in Stackblitz). Here is my code:
page.component.html:
<span *ngFor="let x of fakeArray; let index = index">
<button type="button" class="btn btn-primary" (click)="goToPage(index)"> index + 1 </button>
</span>
<br><br>
<table class="table">
<thead>
<tr>
<th>Alue-ID</th>
<th>Kunta</th>
<th>Lääni</th>
<th>Maakunta</th>
<th>Seutukunta</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let municipality of municipalities">
<td> municipality.alue_id </td>
<td> municipality.kunta </td>
<td> municipality.laani </td>
<td> municipality.maakunta </td>
<td> municipality.seutukunta </td>
</tr>
</tbody>
</table>
<span *ngFor="let x of fakeArray; let index = index">
<button type="button" class="btn btn-primary" (click)="goToPage(index)"> index + 1 </button>
</span>
<br><br>
page.component.ts:
import Component, OnInit from '@angular/core';
import MunicipalitiesService from '../municipalities.service';
import municipality from '../municipality.interface';
import ActivatedRoute, Router from '@angular/router';
@Component(
selector: 'app-page',
templateUrl: './page.component.html',
styleUrls: ['./page.component.css']
)
export class PageComponent implements OnInit
municipalities: municipality[] = [];
pagenumber: number;
fakeArray: any;
constructor(
private service: MunicipalitiesService,
private route: ActivatedRoute,
private router: Router)
ngOnInit()
this.route.params.subscribe(params =>
this.pagenumber = +params.number;
)
this.service.getOneHundredRecords(this.pagenumber).then((data: municipality[]) =>
this.municipalities = data;
);
this.service.getPageCount().then((pageCount: number) =>
this.fakeArray = new Array(pageCount);
)
goToPage = (index: number) =>
this.router.navigate([`/page/$index`]);
municipalities.service.ts:
import Injectable from '@angular/core';
import HttpClient from '@angular/common/http';
import municipality from './municipality.interface';
@Injectable()
export class MunicipalitiesService
constructor(private http: HttpClient)
getOneHundredRecords = (page: number) =>
return new Promise((resolve, reject) =>
this.http.get("/assets/data.json").subscribe((data: municipality[]) =>
let municipalities = data;
let index = 0;
let toBeReturned: municipality[] = [];
for (let municipality of municipalities)
if (index >= (page * 100) && index < (page + 1) * 100)
toBeReturned.push(municipality);
index++;
resolve(toBeReturned)
)
)
getPageCount = () =>
return new Promise((resolve, reject) =>
this.http.get("/assets/data.json").subscribe((data: municipality[]) =>
let municipalities = data;
let index = 0;
for (let municipality of municipalities)
index++;
let pageCount = Math.ceil(index / 100);
resolve(pageCount)
)
)
angular typescript
angular typescript
asked Mar 25 at 19:49
aleksejjjaleksejjj
1531 silver badge11 bronze badges
1531 silver badge11 bronze badges
1
Technically you are still in the same route to the same component, thus it doesn't reload. You can force the reload by doing this:this.router.navigate([
/page/$index]).then(() => window.location.reload());
however i'd advise doing this because it basically removed all your states. So instead of doingnavigate
it is better if you grab your new set data viagoToPage()
method.
– penleychan
Mar 25 at 20:03
add a comment |
1
Technically you are still in the same route to the same component, thus it doesn't reload. You can force the reload by doing this:this.router.navigate([
/page/$index]).then(() => window.location.reload());
however i'd advise doing this because it basically removed all your states. So instead of doingnavigate
it is better if you grab your new set data viagoToPage()
method.
– penleychan
Mar 25 at 20:03
1
1
Technically you are still in the same route to the same component, thus it doesn't reload. You can force the reload by doing this:
this.router.navigate([
/page/$index]).then(() => window.location.reload());
however i'd advise doing this because it basically removed all your states. So instead of doing navigate
it is better if you grab your new set data via goToPage()
method.– penleychan
Mar 25 at 20:03
Technically you are still in the same route to the same component, thus it doesn't reload. You can force the reload by doing this:
this.router.navigate([
/page/$index]).then(() => window.location.reload());
however i'd advise doing this because it basically removed all your states. So instead of doing navigate
it is better if you grab your new set data via goToPage()
method.– penleychan
Mar 25 at 20:03
add a comment |
1 Answer
1
active
oldest
votes
There is a policy with Angular router that prevents you when you want to navigate to the same route from the one that you are currently in.
You could use RouteReuseStrategy like this:
page.component.ts:
***
constructor()
this.router.routeReuseStrategy.shouldReuseRoute = () => false;
***
This will allow your component to refresh after you navigate on her (from her).
Hope this helps!
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%2f55345388%2fthis-router-navigate-doesnt-navigate-to-the-url%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
There is a policy with Angular router that prevents you when you want to navigate to the same route from the one that you are currently in.
You could use RouteReuseStrategy like this:
page.component.ts:
***
constructor()
this.router.routeReuseStrategy.shouldReuseRoute = () => false;
***
This will allow your component to refresh after you navigate on her (from her).
Hope this helps!
add a comment |
There is a policy with Angular router that prevents you when you want to navigate to the same route from the one that you are currently in.
You could use RouteReuseStrategy like this:
page.component.ts:
***
constructor()
this.router.routeReuseStrategy.shouldReuseRoute = () => false;
***
This will allow your component to refresh after you navigate on her (from her).
Hope this helps!
add a comment |
There is a policy with Angular router that prevents you when you want to navigate to the same route from the one that you are currently in.
You could use RouteReuseStrategy like this:
page.component.ts:
***
constructor()
this.router.routeReuseStrategy.shouldReuseRoute = () => false;
***
This will allow your component to refresh after you navigate on her (from her).
Hope this helps!
There is a policy with Angular router that prevents you when you want to navigate to the same route from the one that you are currently in.
You could use RouteReuseStrategy like this:
page.component.ts:
***
constructor()
this.router.routeReuseStrategy.shouldReuseRoute = () => false;
***
This will allow your component to refresh after you navigate on her (from her).
Hope this helps!
answered Mar 25 at 21:55
Milos KovacevicMilos Kovacevic
4661 gold badge4 silver badges8 bronze badges
4661 gold badge4 silver badges8 bronze badges
add a comment |
add a comment |
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.
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%2f55345388%2fthis-router-navigate-doesnt-navigate-to-the-url%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
1
Technically you are still in the same route to the same component, thus it doesn't reload. You can force the reload by doing this:
this.router.navigate([
/page/$index]).then(() => window.location.reload());
however i'd advise doing this because it basically removed all your states. So instead of doingnavigate
it is better if you grab your new set data viagoToPage()
method.– penleychan
Mar 25 at 20:03