jhipster - 在 JHipster 中一起使用 Angular 和 Thymeleaf

标签 jhipster

我们使用 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/

相关文章:

intellij-idea - 将 jHipster 项目导入 intellij

gradle - 在Jhipster中,我通过命令删除了文件,并在运行 “gradlew liquibaseDiffChangelog ”命令后删除了该错误

postgresql - 将 jhipster 远程连接到 postgres

JHipster : Is there a reference documentation for the . yo-rc.json 文件?

java - 为什么在 JHipster 中创建 Spring Bean 时出现错误?

jhipster - 如何在jHipster中创建新的权威?

ubuntu - 如何从 Vagrantfile 更改键盘布局

jhipster - 是否可以告诉 jdl 或 jhipster 使用 Integer 作为 id 类型?

java - Jhipster gradle 构建未加载生产配置文件

node.js - 如何将 jhipster 命令链接到现有存储库?