angular-ui / ui-router

The de-facto solution to flexible routing with nested views in AngularJS
http://ui-router.github.io/
MIT License
13.56k stars 3.01k forks source link

When using "ui-sref" directive ui-router generates wrong urls #3784

Closed Zadvornyi closed 4 years ago

Zadvornyi commented 4 years ago

angular: 1.7.8 @uirouter/angularjs: 1.0.22

my routes are like:

.state('mystate', {
        url: '/some/location',
        ... })

<a href="" ui-sref="mystate">Link</a> Expected Result: <a href="/some/location" ui-sref="mystate">Link</a>

But: <a href="/add-wrong-url/some/location" ui-sref="mystate">Link</a>

I have made some investigation and found function  ` UrlRouter.prototype.href `, in this function there is line ` url = appendBasePath(url, isHtml5, options.absolute, cfg.baseHref());` which add some wrong baseHref to main url.

My solution was to rewrite **_baseHref**, It was correct?:
$transitions.onBefore({}, ($trans) => {
    $transitions._router.locationService._baseHref = '/';
 });
christopherthielen commented 4 years ago

No, that's not correct. Put a <base href="/"> tag in your HTML document