简体   繁体   English

如何使用page.js检查URL并发出路由

[英]How to examine url and emit routing with page.js

Is it possible to emit routing on the current URL, ie, get page.js to call the respective callback on the current path? 是否可以在当前URL上发出路由,即获取page.js来调用当前路径上的相应回调?

The use case for this is if a user is signing in/out of my app, I want page.js to then route on the current path, since the current route may show different views based on authentication status. 这种情况的用例是,如果用户登录/退出我的应用程序,我希望page.js然后在当前路径上进行路由,因为当前路径可能会基于身份验证状态显示不同的视图。

I was using the Riot.js router and just switched over to leverage some page.js features, but page.js seems to be missing this core feature that Riot.js has (see here ). 我使用的是Riot.js路由器,只是切换使用了page.js的某些功能,但是page.js似乎缺少Riot.js的这一核心功能(请参阅此处 )。

ps Currently my workaround is simply location.reload() , but this is not ideal. ps当前,我的解决方法只是location.reload() ,但这并不理想。

You can cause Page to route to any arbitrary URL by simply calling page with the URL. 您可以通过简单地用URL调用Page来使Page路由到任意URL。

So in your case, you might try: 因此,在您的情况下,您可以尝试:

page( location.pathname );

Or if you have some other method of maintaining a method of what route you're currently on: 或者,如果您还有其他方法可以维护当前所走路线的方法:

page( someStorageMechanism.currentRoute );

However, location.reload(); 但是, location.reload(); is unlikely to ever break. 永远也不可能打破。 I would personally consider this ideal, rather than less than ideal. 我个人认为这是理想,而不是不理想。 Why not use the native browser behaviors? 为什么不使用本机浏览器行为?

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

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