X Tutup
Skip to content

PathLocationStrategy._baseHref is null despite APP_BASE_HREF being set in alpha 45. #5028

@kucharskimaciej

Description

@kucharskimaciej

Please consider following, simplified example:

bootstrap:

import {bootstrap, bind} from 'angular2/angular2';
import {
    ROUTER_BINDINGS,
    APP_BASE_HREF,
    ROUTER_PRIMARY_COMPONENT
} from 'angular2/router';

const ROUTER_CONFIG = [
    ROUTER_BINDINGS,
    bind(APP_BASE_HREF).toValue('/'),
    bind(ROUTER_PRIMARY_COMPONENT).toValue(RootComponent)
];

bootstrap(RootComponent, [
    ROUTER_CONFIG
]);

routing:

@RouteConfig([
    {path: "/", as: "Index", component: ItemsIndexComponent},
    {path: "/customers/new", as: "AddCustomer", component: CustomerFormComponent}
])
export class RootComponent {
    constructor(
        public router: Router
    ) {}
}

links:

<a class="btn btn-link" [router-link]="['/Index']">Home</a>
<a class="btn btn-link" [router-link]="['/AddCustomer']">New order</a>

There is no base element on the page. The generated href attributes on links are set to /null and /null/customers/new.

I believe it's because the code in PathLocationStrategy.prepareExternalUrl relies on PathLocationStrategy._baseHref, which is supposed to be set using the DOM adapter, but BrowserDomAdapter.getBaseHref() returns a null if there is no <base /> element in the DOM. The null then get concatenated into the url.

I'm not sure how to fix it at the moment, perhaps setting the PathLocationStrategy._baseHref to an empty string if BrowserDomAdapter.getBaseHref() returns a null would be enough.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      X Tutup