我们使用 JHipster 生成了一个单体应用程序,其中角度页面(OOB 门户)用于管理相关操作,我们使用 Thymeleaf 从头开始构建面向公众的网站。
到今天为止,我们有 localhost:8080/#/用于访问管理门户和 localhost:8080/home 用于公共(public)门户,但我们希望在 localhost:8080/用于公共(public)门户和 localhost:8080/admin 用于管理的地方做其他方式门户网站。
但问题是,一旦我们允许 spring mvc 接受“/”,它就永远不会被重定向到管理门户。有什么解决方案可以做到这一点吗?
最佳答案
在 home.component.ts 中自己进行重定向,如下所示:
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();
}
}
关于jhipster - 在 JHipster 中一起使用 Angular 和 Thymeleaf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45556153/