简体   繁体   English

无法在Polymer 1.0入门套件中进行新的路由(通过page.js和iron-page)

[英]cant make new routing in Polymer 1.0 starter-kit (via page.js and iron-page)

i am new to polymer and i just start it with Polymer 1.0 starter-kit 我是Polymer的新手,我只是从Polymer 1.0入门套件开始

i understand the structure of Polymer app and used the page.js for making a new rout like this. 我了解Polymer应用程序的结构,并使用page.js制作了这样的新记录。

window.addEventListener('WebComponentsReady', function() {

    // We use Page.js for routing. This is a Micro
    // client-side router inspired by the Express router
    // More info: https://visionmedia.github.io/page.js/
    page('/', function () {
      app.route = 'home';
    });

    page('/users', function () {
      app.route = 'artworks';
    });

//my new routing def. <<<<<<<<
    page('/artworks', function () {
      app.route = 'artworks';
    });

    page('/users/:name', function (data) {
      app.route = 'user-info';
      app.params = data.params;
    });

    page('/contact', function () {
      app.route = 'contact';
    });

    // add #! before urls
    page({
      hashbang: true
    });

  });

as i understood the page.js sets the app.route to some values and the Polymer iron-pages uses the app.route to select the right section to show with selected="{{route}}" the code is like this: 据我了解,page.js将app.route设置为某些值,而聚合物铁页使用app.route选择正确的区域以显示与selected="{{route}}"的代码,如下所示:

<iron-pages attr-for-selected="data-route" selected="{{route}}">
  <section data-route="home">home section</section>
  <section data-route="users">users section</section>
  <section data-route="artworks">artworks section</section>
  <section data-route="user-info">user-info section</section>
  <section data-route="contact">contact section</section>
</iron-pages>

after all what is the problem!? 毕竟是什么问题!? well when i use localhost:8000/artworks the page.js wont change it to localhost:8000/#!/artworks but it do just the same for every other routed address like localhost:8000/users or localhost:8000/contact as a result the web browser will search for the file at localhost:8000/artworks folder and finds nothing so a 404 err will occur. 很好,当我使用localhost:8000/artworks artworks时,page.js不会将其更改为localhost:8000/#!/artworks artworks,但对于其他路由地址(例如localhost:8000/userslocalhost:8000/contact ,它的作用相同结果,Web浏览器将在localhost:8000 / artworks文件夹中搜索文件,但未找到任何内容,因此将发生404错误。

i can not understand now. 我现在不明白。 what did i missed here? 我在这里错过了什么? any idea? 任何想法?

i don't know exactly why but it seems that the Polymer were not reading the routing file at all! 我不知道为什么,但是似乎Polymer根本没有读取路由文件! so i just copy-pasted the routing code in my app.js file and everything works normal now! 所以我只是将路由代码复制粘贴到我的app.js文件中,现在一切正常!

so now my app.js has all the routing codes at the end and i also attached the page.js in the head of my index.html(the main file of Polymer app) 因此,现在我的app.js在末尾具有所有路由代码,而且我还将page.js附加在了index.html(Polymer应用程序的主文件)的开头

i have no idea why, but it's working now. 我不知道为什么,但是现在正在工作。

Not sure if this would work, but maybe using relative addresses based on your port might help. 不知道这是否行得通,但是也许根据您的端口使用相对地址可能会有所帮助。 For example try something like app.route = window.location.protocol + '//' + window.location.hostname + ":8000" + window.location.pathname + "home"; 例如,尝试类似app.route = window.location.protocol +'//'+ window.location.hostname +“:8000” + window.location.pathname +“ home”之类的东西;

I had the same problem, and it appears to be a problem of cache ; 我有同样的问题,似乎是缓存问题; the routing.html page was cached by navigator, so new routes were not seen. routing.html页面由导航器缓存,因此看不到新的路由。 Clearing the cache resolved my problem. 清除缓存解决了我的问题。 Hope this helps ! 希望这可以帮助 !

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM