代码之家  ›  专栏  ›  技术社区  ›  Typel

聚合物1.0-如何使用“页面”路由应用程序并更改URL

  •  2
  • Typel  · 技术社区  · 9 年前

    使用Polymer 1.0 Starter Kit,我想建立一条新路线,但我需要从我的应用程序中的一个功能启动它。js文件而不是通过routing.html

    app._loadProject = function(e) {
      // do stuff here
      // after finished, route to our 'project' section in the app
      app.route = 'project';
    };
    

    这在很大程度上起作用。应用程序被路由到“项目” <section> 然而,URL不会更新以反映这一点,因此在用户重新加载页面的情况下,他们会发现自己所在的“部分”与刚刚所在的部分不同-这不是最友好的场景。

    有没有一种更合适的方法来使用“页面”进行路由,而不会破坏浏览器导航?

    1 回复  |  直到 9 年前
        1
  •  3
  •   Kayce Basques    9 年前

    做你的事 app.js :

    app._loadProject = function(e) {
      // do stuff here
      // after finished, route to our 'project' section in the app
      page.show('/project'); // same as page('/project')
    };
    

    在中添加规则 routing.html :

    page('/project', project);
    ...
    function project() {
      app.route = 'project';
    }
    
    推荐文章