Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Polymer 1.0 rewrites links to be relative to source document rather than page. #2448

Closed
augustoroman opened this issue Sep 17, 2015 · 4 comments

Comments

@augustoroman
Copy link

In polymer 1.0, my elements that have links in the template dom are re-written to be relative to where the element is loaded rather than relative to the current browser location.

That is, if (in my element) I have:

  <a href="/about">About us</a>

and the page is at http://widgets.com/ but the static content is served from http://cdn.com/path/to/content/, the link will point to http://cdn.com/about instead of http://widgets.com/about.

This appears to be occurring due to the urlResolver code:

    function resolve(url, ownerDocument) {
        if (url && url[0] === '#') {
            return url;
        }
        var resolver = getUrlResolver(ownerDocument);
        resolver.href = url;
        return resolver.href || url;
    }
    function getUrlResolver(ownerDocument) {
        return ownerDocument.__urlResolver || (ownerDocument.__urlResolver = ownerDocument.createElement('a'));
    }

which is getting applied to my element.

A workaround at the moment is to inject the url via data-binding to a computed function, e.g.:

  <a href="{{str('/about')}}">About us</a>

with

  str: function(s) { return s; },

in my element... but that's just silly.

@oderby
Copy link

oderby commented Nov 6, 2015

Bump. This is a big gotcha that's bitten me a few times.

@dfreedm dfreedm self-assigned this Nov 12, 2015
@dfreedm dfreedm added the p1 label Nov 12, 2015
@kevinpschaaf
Copy link
Member

Absolute paths should not be rewritten -- this should be fixed.

@kevinpschaaf kevinpschaaf added this to the Q1 milestone Feb 18, 2016
@ktiedt
Copy link
Contributor

ktiedt commented Jul 27, 2016

Ping @azakus / @tjsavage -- This has been a hot topic in the Slack channel today, It seems most people were not inclined to +1 this but, it does seem like a pretty important issue to address.

@aletorrado
Copy link

aletorrado commented Jul 27, 2016

It definitely should not behave different when using computed binding like this:

<iron-ajax
    url="/api/v1[[endpoint]]"
></iron-ajax

(this way it's resolved against the page)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants