【问题标题】:Using Angular & Thymeleaf together in JHipster在 JHipster 中一起使用 Angular 和 Thymeleaf
【发布时间】:2018-01-15 07:19:48
【问题描述】:

我们使用 JHipster 生成了一个单体应用程序,其中角度页面(OOB 门户)用于管理相关操作,我们使用 Thymeleaf 从头开始​​构建面向公众的网站。

截至今天,我们有 localhost:8080/#/ 用于访问管理门户和 localhost:8080/home 用于公共门户,但我们希望在 localhost:8080/ 用于公共门户和 localhost:8080/ 的地方做其他方式admin 用于管理门户。

但问题是,一旦我们允许 spring mvc 接受“/”,它就永远不会被重定向到管理门户。有什么解决办法吗?

【问题讨论】:

    标签: jhipster


    【解决方案1】:

    在 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();
        }
    }
    

    【讨论】:

    • 感谢您的回复。我尝试在 home.component.ts 文件中使用上面的代码,但这并没有改变很多功能。管理门户仍然在 localhost:8080 上打开,并且 localhost:8080/admin 页面抛出 500 错误。
    猜你喜欢
    • 1970-01-01
    • 2023-03-03
    • 2017-03-13
    • 2018-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-31
    • 1970-01-01
    相关资源
    最近更新 更多