Angular url change does not cause the component to be recreated

user1238784

I have a component that lists a series of data and needs paging, because the list of data can be long. I have implemented a simple paging using the route. For example:

http://localhost:50367/searchflights/2

Will give me the second page of data. Now if I type the url manually in the browser and press enter the component is forced to be recreated and for this reason the data are loaded in the constructor. But If I am already on the page of the component and via Router link change the url, only the url changes and the component is not recreated therefore data are not reloaded.

My paging consists in a simple list of links at the bottom of page:

<div>
        <a style="display:inline-block" *ngFor="let page of pages" [routerLink]="['/searchflights/',page]">
            {{page}}
        </a>
    </div>

If I click on one of the paging links, the route is changed accordingly but data are not reloaded. How can I force the recreation of the component or which event should I hook to in order to reload the data

user4521733

You can subscribe to the route parameters instead of loading data in the constructor.

this.route.params.subscribe(params => {
  this.loadUser(params.id);
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Change in redux state does not cause change in component / componentDidUpdate not called

Why does a hook state change cause component to render?

angular 4 change home page url and component

Angular2 pathLocationStrategy: url change cause page reload

media player does not load when activity is recreated on orientation change

Reactjs - changing url using react router but the component does not change

focus does not change after new component load angular

angular 2 manipulate data in a service does not change that in second component

Angular child component does not recognize change in input property

Angular 6 - html element background color does not change with component

Why does "return !1" in a jquery code block cause the url not to change for an anchor tag linked to another part of the page?

Angular Router does not load my component despite correct URL

Change view/component but not url

Change URL in component action

What conditions cause an Angular component rendering?

Why does my activity seemingly crash after being recreated but not on orientation change?

An angular component does not remain

Why does a = b cause b to change?

Angular model does not change(update) after changing url

does container gets recreated in ECS

Why does Route with children as components cause Typeerror, but route with component does not?

Why does one function cause component to rerender but the other does not Nextjs?

React Router URL Change but Not Component

React Component does not change output

Is my React component being recreated instead of updating?

Angular Change Component Declarations Location

How to change icon in angular component

Angular change the wrapper for a component conditionally

Angular 2—change component selector