【问题标题】:Why does the router redirect to another route when a refresh happens?为什么刷新发生时路由器会重定向到另一条路由?
【发布时间】:2016-03-11 11:24:12
【问题描述】:

我有一个使用 Ember JS、Firebase 和 Torii Adapter 构建的调查应用程序,用于身份验证和会话管理。我试图了解刷新时特定路线(称为“takesurvey”路线)的行为。

来自路由器地图(router.js)的相关代码如下:

this.route('user', function() {
    this.route('surveys');
    //the code below works but on refresh, 
    //nests the takesurvey page under user
    this.route('takesurvey', {path: ':survey_id', resetNamespace: true}); 
  });
   //alternatively, uncommenting the line below redirects to user.surveys on refresh of page
   //this.route('takesurvey', {path: ':survey_id'}); 

这是两个场景的问题(在上面的代码中也描述为 cmets):

场景 1:问卷调查页面作为独立路径保留

在这种情况下,当用户导航到 http://<application name> /survey_id 时,参加调查页面可以正常加载。但是在刷新页面时,它会将用户带回user/surveys 页面。

场景 2:takesurvey 路线嵌套在用户路线下方。

在这种情况下,当用户导航到 http://<application name> /user/survey_id 时,调查加载正常,并且刷新也按预期工作。

所以我的问题是,为什么会发生这种情况?

理想情况下,根据当前要求,我希望将问卷调查页面保留为独立路线,并且当用户在该问卷调查页面上单击刷新时,它应该继续出现在同一页面上,而不是将他重定向到用户/调查页面。

【问题讨论】:

    标签: ember.js


    【解决方案1】:

    我认为问题在于您覆盖了takesurvey 路由的路径。

    将您的路由器更改为如下所示,如果适合您,请告诉我:

    this.route('user', function() {
      this.route('surveys');
      this.route('takesurvey', {path: 'takesurvey/:survey_id', resetNamespace: true}); 
    });
    

    【讨论】:

      猜你喜欢
      • 2017-12-18
      • 1970-01-01
      • 1970-01-01
      • 2017-07-27
      • 1970-01-01
      • 2012-01-21
      • 2020-06-15
      • 2018-03-25
      • 2019-05-13
      相关资源
      最近更新 更多