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.
Please consider following, simplified example:
bootstrap:
routing:
links:
There is no
baseelement on the page. The generatedhrefattributes on links are set to/nulland/null/customers/new.I believe it's because the code in
PathLocationStrategy.prepareExternalUrlrelies onPathLocationStrategy._baseHref, which is supposed to be set using the DOM adapter, butBrowserDomAdapter.getBaseHref()returns anullif there is no<base />element in the DOM. Thenullthen get concatenated into the url.I'm not sure how to fix it at the moment, perhaps setting the
PathLocationStrategy._baseHrefto an empty string ifBrowserDomAdapter.getBaseHref()returns anullwould be enough.