From 5ce3f0bcb88470c0b57b04e7db6fedfdc5a01149 Mon Sep 17 00:00:00 2001 From: Braun Patrik Date: Sun, 27 Mar 2016 21:21:47 +0200 Subject: [PATCH] history navigation i,proved --- frontend/app/app.component.ts | 18 ++++++++++++------ .../directory/directory.gallery.component.html | 2 +- frontend/app/gallery/gallery.component.ts | 9 ++++----- frontend/app/login/login.component.ts | 2 +- frontend/index.html | 2 +- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/frontend/app/app.component.ts b/frontend/app/app.component.ts index 94337045..ed8f3717 100644 --- a/frontend/app/app.component.ts +++ b/frontend/app/app.component.ts @@ -18,7 +18,7 @@ import {GeneratedUrl} from "angular2/src/router/rules/route_paths/route_path"; @Component({ selector: 'pi-gallery2-app', template: ``, - directives: [ROUTER_DIRECTIVES], + directives: [ROUTER_DIRECTIVES, RouterLink], providers: [ HTTP_PROVIDERS, ROUTER_PROVIDERS, @@ -33,12 +33,17 @@ import {GeneratedUrl} from "angular2/src/router/rules/route_paths/route_path"; name: 'Login', component: LoginComponent, useAsDefault: true - }, + }, { - regex: '/gallery(/([\S]*))?', + path: '/gallery', + name: 'GalleryBase', + component: GalleryComponent + }, + { + regex: 'gallery/([\w]*)', name: 'Gallery', serializer: (params): GeneratedUrl => { - return new GeneratedUrl(`/gallery/${params['directory']}`, {}) + return new GeneratedUrl(`gallery/${params['directory']}`, {}) }, component: GalleryComponent } @@ -46,13 +51,14 @@ import {GeneratedUrl} from "angular2/src/router/rules/route_paths/route_path"; export class AppComponent implements OnInit{ constructor(private _router: Router, private _location:Location, private _authenticationService: AuthenticationService){ + } ngOnInit() { this._authenticationService.OnAuthenticated.on((user:User) => { - this._location.replaceState('/'); // clears browser history so they can't navigate with back button - this._router.navigate(["Gallery",{directory:"/"}]); + // this._location.replaceState('/'); // clears browser history so they can't navigate with back button + this._router.navigate(["GalleryBase"]); }); } diff --git a/frontend/app/gallery/directory/directory.gallery.component.html b/frontend/app/gallery/directory/directory.gallery.component.html index 69fa3efa..9c159103 100644 --- a/frontend/app/gallery/directory/directory.gallery.component.html +++ b/frontend/app/gallery/directory/directory.gallery.component.html @@ -1 +1 @@ -{{directory.name}} \ No newline at end of file +{{directory.name}} \ No newline at end of file diff --git a/frontend/app/gallery/gallery.component.ts b/frontend/app/gallery/gallery.component.ts index df71a461..497b500f 100644 --- a/frontend/app/gallery/gallery.component.ts +++ b/frontend/app/gallery/gallery.component.ts @@ -23,18 +23,17 @@ export class GalleryComponent implements OnInit{ private _params: RouteParams, private _authService: AuthenticationService, private _router: Router, - private _location:Location) { - + private _location:Location) { } ngOnInit(){ if (!this._authService.isAuthenticated()) { - this._location.replaceState('/'); // clears browser history so they can't navigate with back button + // this._location.replaceState('/'); // clears browser history so they can't navigate with back button this._router.navigate(['Login']); return; } - console.log(this._params.get('directory')); - let directoryName = this._params.get('directory'); + + let directoryName = this._params.get('directory'); directoryName = directoryName ? directoryName : ""; this._galleryService.getDirectory(directoryName).then(( message:Message) => { if(message.error){ diff --git a/frontend/app/login/login.component.ts b/frontend/app/login/login.component.ts index 512dcf94..13d50db2 100644 --- a/frontend/app/login/login.component.ts +++ b/frontend/app/login/login.component.ts @@ -18,7 +18,7 @@ export class LoginComponent implements OnInit{ ngOnInit(){ if (this._authService.isAuthenticated()) { - this._location.replaceState('/'); // clears browser history so they can't navigate with back button + // this._location.replaceState('/'); // clears browser history so they can't navigate with back button this._router.navigate(['Gallery']); } } diff --git a/frontend/index.html b/frontend/index.html index 679b0f70..f33b7c2e 100644 --- a/frontend/index.html +++ b/frontend/index.html @@ -43,6 +43,6 @@ Loading... - + \ No newline at end of file