Reputation: 1404
We generated a monolithic application using JHipster, where angular pages (OOB portal) are used for admin related operations and we built public facing website from scratch using Thymeleaf.
As of today we have localhost:8080/#/ is used to access admin portal and localhost:8080/home for public portal but we want to do other way around where localhost:8080/ for public portal and localhost:8080/admin for admin portal.
But the problem is that once we allow spring mvc to accept '/', then it never gets redirected to admin portal. Is there any solution to do this?
Upvotes: 4
Views: 1098
Reputation: 1998
Make the redirection yourself in home.component.ts like below:
import { Component, OnInit } from '@angular/core';
import { NgbModalRef } from '@ng-bootstrap/ng-bootstrap';
import { JhiEventManager } from 'ng-jhipster';
import { Account, LoginModalService, Principal } from '../shared';
import {Router} from '@angular/router';
@Component({
selector: 'jhi-home',
templateUrl: './home.component.html',
styleUrls: [
'home.css'
]
})
export class HomeComponent implements OnInit {
account: Account;
modalRef: NgbModalRef;
constructor(
private principal: Principal,
private loginModalService: LoginModalService,
private eventManager: JhiEventManager,
private router: Router,
) {
}
ngOnInit() {
this.principal.identity().then((account) => {
this.account = account;
});
this.registerAuthenticationSuccess();
}
registerAuthenticationSuccess() {
this.eventManager.subscribe('authenticationSuccess', (message) => {
this.principal.identity().then((account) => {
this.account = account;
// The redirection to /admin
this.principal.hasAnyAuthority(['ROLE_ADMIN']).then((result) => {
if (result) {
this.router.navigate(['/admin']);
}
});
});
});
}
isAuthenticated() {
return this.principal.isAuthenticated();
}
login() {
this.modalRef = this.loginModalService.open();
}
}
Upvotes: 1