简体   繁体   English

polymer / page.js在javascript中更改路由而不会导致页面刷新

[英]polymer / page.js change route in javascript without causing page refresh

I use Polymer starter kit to build my app. 我使用Polymer入门套件来构建我的应用程序。 I removed the hashbang in the urls. 我删除了网址中的hashbang。

I am trying to build a login screen and after successful login, I want to change the page to default route. 我正在尝试构建登录屏幕,并且在成功登录后,我想将页面更改为默认路由。 To do this, I have a listener in app.js for successful log in. On successful log in, I change the route which causes page refresh. 为此,我在app.js中有一个监听器,用于成功登录。成功登录后,我更改了导致页面刷新的路由。 I tried multiple options: 我尝试了多种选择:

  1. location = 'entireUrl' location ='wholeUrl'
  2. location.pathname = '/route' location.pathname ='/ route'
  3. location = 'route' location ='route'

All the options causes page refresh. 所有选项都会导致页面刷新。 Is there any way to code this without causing page refresh. 有没有办法在不导致页面刷新的情况下对此进行编码。 Shouldn't page.js catch this and do the routing without page refresh? 不应该page.js抓住这个并在没有页面刷新的情况下进行路由吗?

For those looking for an answer, I fixed it by calling page.redirect('/route'). 对于那些寻找答案的人,我通过调用page.redirect('/ route')来修复它。

note: page.redirect will replace the browser history. 注意:page.redirect将替换浏览器历史记录。 If you want to retain browser history you can use page.show('/route') 如果要保留浏览器历史记录,可以使用page.show('/ route')

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

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