Base solution for your next web application
Open Closed

Angular application routing issue when using relative path #11709


User avatar
0
henriksorensen created

We've run into an issue with handling an issue on the angular side when our angular application has a relative path like /application/, for example, http://localhost/application/

The default ASP.NET Zero handler redirects the user according to the following code (zero-template-http-configuration.service.ts):

import { Injectable } from '@angular/core'; import { AbpHttpConfigurationService, LogService, MessageService } from 'abp-ng2-module'; import { Router } from '@angular/router';

@Injectable({ providedIn: 'root', }) export class ZeroTemplateHttpConfigurationService extends AbpHttpConfigurationService { constructor(messageService: MessageService, logService: LogService, private _route: Router) { super(messageService, logService); }

// Override handleUnAuthorizedRequest so it doesn't refresh the page during failed login attempts.
handleUnAuthorizedRequest(messagePromise: any, targetUrl?: string) {
    if (this._route.url && (
        this._route.url.startsWith('/account/login') || this._route.url.startsWith('/account/session-locked')
    )) {
        return;
    }

    const self = this;

    if (messagePromise) {
        messagePromise.done(() => {
            this.handleTargetUrl(targetUrl || '/');
        });
    } else {
        self.handleTargetUrl(targetUrl || '/');
    }
}

}

Actual result

The redirect occurs to the domain name and does not take into account the relative path.

Expected result After the redirect, the user is redirected to the correct root URL

So, could you please provide us: 1. How to pass targetUrl argument to this method? In our case it is NULL

2. Or how can we solve the problem with an application whose relative path is different from the domain name = '/'?


3 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Could you use abp.appPath instead of / and see if it works ?

  • User Avatar
    0
    henriksorensen created

    Hello We fixed this problem in a slightly different way using the AppUrlService.appRootUrl service property. But we are still wondering if there are ways to fix this problem without modifying the code? Or should we expect a fix for this problem in future versions of ASP.NET Zero?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @henriksorensen

    Yes, this should be working out of the box. It has been fixed via https://github.com/aspnetzero/aspnet-zero-core/commit/6f980db0037365835d9437e1f63d03c920fabff7