I'm having some difficulties to use pretty Urls in my application which is Polymer 100% app and powered by Firebase. It's based on Polymer Starter Kit 1.2.0.
I'm wanting to access the route localhost:5000/user/edit
. If I'm in the home page (localhost:5000) and click in a button with a href="/user/edit"
it works fine. But, if I refresh the page of if I go directly to the "/user/edit"
route without passing by the home page, appears a lot of problems related to find the files. The console shows the following:
edit:36 GET http://localhost:5000/user/styles/main.css edit:37 GET
http://localhost:5000/user/styles/pikaday.css edit:41 GET
http://localhost:5000/user/bower_components/webcomponentsjs/webcomponents-lite.js
edit:45 GET http://localhost:5000/user/elements/elements.html 404 (Not
Found)
My app.js file has only these lines:
var app = document.querySelector('#app');
app.baseUrl = '/';
And my routing.html is:
<script>
window.addEventListener('WebComponentsReady', function() {
// Removes end / from app.baseUrl which page.base requires for production
if (window.location.port === '') { // if production
page.base(app.baseUrl.replace(/\/$/, ''));
}
// Routes
page('/', function() {
app.route = 'home';
});
page(app.baseUrl, function() {
app.route = 'home';
});
page('/user/edit', function() {
app.route = 'user/edit';
});
page('*', function() {
console.info('404 page');
page.redirect(app.baseUrl);
});
// add #! before urls
page({
hashbang: false
});
});
</script>
I tried a lot of things:
- If I change the route
/user/edit
touser-edit
, it works fine. Apparently the problem is related to the '/' in the route. - If I set hashbang to true, it also works fine. But, I'm really wanting to work pretty URLs in my application.
- If in the index.html I change
<link rel="import" href="elements/elements.html">
to<link rel="import" href="/elements/elements.html">
the browser finds all the elements, but routing continues with the same problem.
Any ideas about how to solve this problem? I believe that it will help a lot of people who also wants to work with pretty URLs