简体   繁体   English

聚合物铁页面pagejs不起作用

[英]polymer iron-pages pagejs not working

I am implementing a simple routing app in polymer.js using iron-pages and page.js but this is not working. 我正在使用iron-pages和page.js在polymer.js中实现一个简单的路由应用程序,但这不起作用。

 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <script src="/bower_components/webcomponentsjs/webcomponents-loader.js"></script> <link rel="import" href="/bower_components/polymer/polymer.html"> <link rel="import" href="/bower_components/iron-pages/iron-pages.html"> <link rel="import" href="routes.html"> <title>Document</title> </head> <body> <div is="dom-bind" id="app"> <a data-route="home" href="/">home</a> <a data-route="users" href="/users">users</a> <a data-route="settings" href="/settings">settings</a> <iron-pages attr-for-selected="data-route" selected="{{route}}"> <section data-route="home">Home</section> <section data-route="users">Users</section> <section data-route="settings">Settings</section> </iron-pages> </div> </body> </html> 

 <script src="/bower_components/page/page.js"></script> <script> window.addEventListener('WebComponentsReady', function() { page('/', function() { app.route = 'home' console.log(app.route) // console.log('home') }) page('/users', function () { app.route = 'users' }) page('/settings', function () { app.route = 'settings' }) page({ hashbang: false }) }) </script> 

Everything seems okay but this is not working. 一切似乎都还不错,但这不起作用。

At first, you should NOT use iron-pages in index.html.. It's much more easier and in future of your application also necessary to create new element where is located all the structure logic (routing, some popup elements etc...). 首先,您不应该在index.html中使用Iron-pages。这要容易得多,在将来的应用程序中,还需要在所有结构逻辑(路由,某些弹出元素等)中创建新元素。 。

Dom-bind is only temporary solution. Dom-bind只是临时解决方案。 Your code seems ok and there should be no problem. 您的代码似乎没问题,应该没有问题。

I assume you have your .htaccess configured as it is necessary to have it when using page.js 我假设您已经配置了.htaccess ,因为使用page.js时需要配置它

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

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