1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-12 11:15:22 +02:00

history navigation i,proved

This commit is contained in:
Braun Patrik 2016-03-27 21:21:47 +02:00
parent f8db033c56
commit 5ce3f0bcb8
5 changed files with 19 additions and 14 deletions

View File

@ -18,7 +18,7 @@ import {GeneratedUrl} from "angular2/src/router/rules/route_paths/route_path";
@Component({
selector: 'pi-gallery2-app',
template: `<router-outlet></router-outlet>`,
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"]);
});
}

View File

@ -1 +1 @@
<a [routerLink]="['Gallery',{directory: getDirectoryPath()}]">{{directory.name}}</a>
<a [routerLink]="['/Gallery',{directory: getDirectoryPath()}]">{{directory.name}}</a>

View File

@ -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<Directory>) => {
if(message.error){

View File

@ -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']);
}
}

View File

@ -43,6 +43,6 @@
<body>
<pi-gallery2-app>Loading...</pi-gallery2-app>
</body>
<script src="https://code.angularjs.org/2.0.0-beta.10/angular2-polyfills.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.12/angular2-polyfills.js"></script>
<script src="dist/app-bundle.js"></script>
</html>