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;








1















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)
)
)












share|improve this question

















  • 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


















1















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)
)
)












share|improve this question

















  • 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














1












1








1








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)
)
)












share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 doing navigate it is better if you grab your new set data via goToPage() method.

    – penleychan
    Mar 25 at 20:03













  • 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








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













1 Answer
1






active

oldest

votes


















1














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!






share|improve this answer






















    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%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









    1














    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!






    share|improve this answer



























      1














      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!






      share|improve this answer

























        1












        1








        1







        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!






        share|improve this answer













        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!







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 25 at 21:55









        Milos KovacevicMilos Kovacevic

        4661 gold badge4 silver badges8 bronze badges




        4661 gold badge4 silver badges8 bronze badges


















            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.



















            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%2f55345388%2fthis-router-navigate-doesnt-navigate-to-the-url%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

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현