tom10271
tom10271

Reputation: 4649

How to transit to other routes using the same component without destroying and reinitializing Component?

I have a ProfileComponent, inside the page user can click on letters to filter profile start with it.

Entry Point: /profile

A B C ... X Y Z

When user click on these letters -> url: /profile -> /profile/;startWith=X.

I want to keep the startWith parameters in URL, however I notice Angular 2 will destroy current component then recreate and initialize the same component again. How to keep URL params without reinitializing component?

Upvotes: 2

Views: 174

Answers (1)

Günter Zöchbauer
Günter Zöchbauer

Reputation: 657416

If you implement CanReuse

routerCanReuse(next: ComponentInstruction, prev: ComponentInstruction) { return true; }

in your component, the router should keep the same instance instead of re-creating a new one.

Upvotes: 1

Related Questions