我已经安装了 polymer 入门套件,一旦加载入门套件,所有东西都会正确加载,并且网址看起来像 http://127.0.0.1:8887/然后,一旦我单击任何 View ,该页面就会打开,并且 url 更改为 http://127.0.0.1:8887/view1但如果我现在重新加载浏览器,它不会显示相同的页面,而是显示条目未找到错误。我尝试通过互联网搜索解决方案,但没有找到。我应该做什么来修复它。
最佳答案
当您刷新页面 ( http://127.0.0.1:8887/view1 ) 时,您向服务器请求 view1
资源,但服务器找不到它,因为不存在。该路径 (.../view1
) 仅能被 polymer 应用程序本身识别,而不能被服务器识别。
尝试在路径中使用哈希。将 use-hash-as-path
属性添加到主页内的 app-location
元素。
所以,它应该看起来像这样:
<app-location route="{{route}}" use-hash-as-path></app-location>
编辑
仅添加 use-hash-as-path
属性是不够的。您还需要稍微更改菜单项中的 href
。
href="/view1"
到 href="#/view1"
包含更多详细信息的代码:
<app-location route="{{route}}" use-hash-as-path></app-location>
<app-route
route="{{route}}"
pattern="/:page"
data="{{routeData}}"
tail="{{subroute}}"></app-route>
<app-drawer-layout fullbleed>
<!-- Drawer content -->
<app-drawer>
<app-toolbar>Menu</app-toolbar>
<iron-selector selected="[[page]]" attr-for-selected="name" class="drawer-list" role="navigation">
<a name="view1" href="#/view1">View One</a>
<a name="view2" href="#/view2">View Two</a>
<a name="view3" href="#/view3">View Three</a>
</iron-selector>
</app-drawer>
...
</app-drawer-layout>
关于重新加载时 polymer 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39608956/