mardi 14 juin 2016

Store HTML page in memory with Angular2

I would like to keep web page in memory so that when I click on back button (not the one on web browser) or on a routerlink, the HTML page instantly loads if I already visit it(because I have some data to load that I don't want to be reload).

I've seen a method with tabbed interface : https://www.w3.org/Style/Examples/007/target.en.html#tab1 but it is not adapted for my code architecture.

I'm using routerlinkin angular2 to navigate threw pages and a back button calling a function on click to go to the previous page.

I try to detail as far as I can so people can understand better my code architecture and the way routerlink method works.

Back button function (works independently from routerlink) :

 goBack() {
 window.history.back();
 }

The router link method from page 1 to page 2:

page1.html :

<a[routerLink]="['PAGE2']"> go to page 2</a>

page1.ts component:

 import { Router, ROUTER_DIRECTIVES } from '@angular/router-deprecated';
 @Component({
 selector: 'page1',
 templateUrl: 'page1.html',
 styleUrls:  ['page1.css'],
 directives: [ROUTER_DIRECTIVES]
 })

main.ts :

import { RouteConfig, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '@angular/router-deprecated';

@Component({
providers: [ROUTER_PROVIDERS]
})

@RouteConfig([
{ path: '/page2',  name: 'PAGE2',  component: Page2}]) //component representing class Page2 in page2.ts

Any idea to help me manage it is welcomed, thanks by advance !

Aucun commentaire:

Enregistrer un commentaire