If I take the Polymer starter kit, it works well locally. I can navigate to http://localhost:8080/ and all the links to the 3 views work fine.
Now, if I host this app on a web server (that is shared with other apps) on a URL such as http://myservername:8080/mywonderfulapp/, I am having trouble with the routing. Is there a way I can mention the app-route to take in the relative URL?
I tried making changes to the html files to have relative URLs
<link rel="import" href="./src/my-app.html">
<a name="view1" href="./view1">View One</a>
<base href="/mywonderfulapp/">
but I cant seem to fix the app-routing in a similar fashion.
All similar questions here on SO seem to be about a pre-1.0 version of Polymer, and mention page.js and hash-bang routing instead of the HTML5-history-friendly URLs and the app-route component.
I would prefer to make minimal code changes to ensure
- the same code works locally as well as on the remote host
- the app is not dependent on the base URL on which it is hosted - so, preferably I dont have to mention "mywonderfulapp" (from the URL above) anywhere in the code.
The closest I got with this so far, is to:
mention a placeholder for a URL prefix in the app-route pattern.
and then use that in the
href
attribute for the anchorThe drawback with this approach is that I have to use the URL as http://localhost:8080/mywonderfulapp/ even when working locally, but at least I don't have to modify code anymore when deploying to my remote web server.
As stated in the comments, this was solved in a similar posting on stackoverflow.com/questions/39608956/polymer-error-on-reloading
Side note for firebase users - if you deploy this same version of starter kit to firebase and do a firebase serve at the CLI, this problem will even occur in the localhost, so you will need the above fix, even for there.