2014-10-17 3 views
1

내 백본 마리오 네트 앱에서 이상한 시나리오가 있습니다. 사용자가 페이스 북/트위터 링크를 클릭 한 다음 브라우저의 뒤로 버튼을 클릭하면 내 앱을 다시로드하는 대신 example.com/posts 대신 example.com/posts.json으로 간 것처럼 json이 표시됩니다. 사용자가 페이지를 수동으로 다시로드하면 잘로드되지만 사용자가 json을 보는 것은 매우 혼란 스럽습니다.뒤로 버튼이 백본 응용 프로그램을 다시 트리거하지 않습니다.

내가 example.com/posts에 있고 수동으로 멀리 이동하여 gmail.com이라고 말하고 뒤로 버튼을 클릭하면 제대로 작동합니다. 이 시나리오가 발생하면 내 앱 내의 링크를 클릭하는 것 같습니다.

내 앱으로 돌아 가기 위해 뒤로 버튼을 클릭 할 때 어떻게 백본 앱을 다시로드 할 수 있습니까?

편집 :

내 레일 컨트롤러를 추가 -이 인덱스를 때리고. 하지만 (같은 페이지 새로 고침가 올바른 HTML 명중하는 원인이 있지만) html로 대 JSON을 트리거 것 같다 뒤로 버튼을 타격 할 때 :

class SurveysController < ApplicationController  
    # GET /surveys 
    # GET /surveys.json 
    def index 
    if cookies[:sample_user_id] && !User.find(cookies[:sample_user_id]).admin? 
     if !cookies[:sample_appuser_token] 
     appuser = Appuser.create 
     sign_in_appuser appuser 
     else 
     appuser = current_appuser 
     end 
     @surveys = User.find(cookies[:sample_user_id]).surveys.includes([:responses => [:choices], :questions => [:answers]]) 
    else 
     if !cookies[:sample_appuser_token] 
     appuser = Appuser.create 
     sign_in_appuser appuser 
     else 
     appuser = current_appuser 
     end 
     @surveys = Survey.where(status: "Submitted") 
     if cookies[:sample_user_id] 
     User.find(cookies[:sample_user_id]).surveys.each do |survey| 
      @surveys << survey 
     end 
     end 
    end 
    end 

그리고 index.html.erb보기 :

<div id="wrap"> 
    <div id="header-region"></div> 
    <div id="main-region"></div> 
    <div id="push"></div> 
</div> 
<div id="footer-region"></div> 
<div id="dialog-region"></div> 
<%= debug(params) if Rails.env.development? %> 

<%= javascript_tag do %> 
    $(function() { 
    Sample.start({ 
     environment: "<%= Rails.env %>" 
    }); 
    }); 
<% end %> 

SurveysRouter :

@Sample.module "SurveysApp", (SurveysApp, App, Backbone, Marionette, $, _) -> 

    class SurveysApp.Router extends Marionette.AppRouter 
    appRoutes: 
     ""   : "list" 
     ":id"   : "show" 
     ":id/take": "take" 

    API = 
    list: -> 
     if $.cookie('sample_user_email') != null 
     new SurveysApp.List.Controller 
     else 
     window.location = "/signin" 

    show: (id) -> 
     window.fragment = Backbone.history.fragment 
     if $.cookie('sample_user_email') != null 
     new SurveysApp.Show.Controller 
      id: id 
     else 
     console.log Backbone.history.fragment 
     window.location = "/signin" + "#" + window.fragment 

    take: (id, survey) -> 
     new SurveysApp.Take.Controller 
     id: id 
     survey: survey 

    newSurvey: (surveys, survey) -> 
     if $.cookie('sample_user_email') != null 
     new SurveysApp.New.Controller 
      surveys: surveys 
      survey: survey 
     else 
     window.location = "/signin" 

    App.vent.on "survey:clicked", (survey) -> 
    App.navigate "/" + survey.id 
    API.show survey.id 

    App.vent.on "new:survey", (surveys, survey) -> 
    API.newSurvey surveys, survey 

    App.vent.on "take:survey:button:clicked", (survey) -> 
    App.navigate "/" + survey.id + "/take" 
    API.take survey.id, survey 

    App.vent.on "survey:list", -> 
    App.navigate "/" 
    API.list() 

    App.addInitializer -> 
    new SurveysApp.Router 
     controller: API 

목록 컨트롤러 :

@Sample.module "SurveysApp.List", (List, App, Backbone, Marionette, $, _) -> 

    class List.Controller extends App.Controllers.Application 

    initialize: -> 
     surveys = App.request "survey:entities" 

     App.execute "when:fetched", surveys, => 
      @layout = @getLayoutView() 

      @listenTo @layout, "show", => 
      @surveyRegion surveys 
      @bannerRegion surveys 

     @show @layout 
     App.request "header:footer" 

    surveyRegion: (surveys) -> 
     surveyView = @getSurveyView surveys 

     @listenTo surveyView, "childview:survey:clicked", (args) -> 
     if args.model.get('status') == "Draft" 
      App.vent.trigger "new:survey", surveys, args.model 
     else 
      App.vent.trigger "survey:clicked", args.model 


     @listenTo surveyView, "childview:take:survey:button:clicked", (child, args) -> 
     survey = args.model 
     survey.set(preview: true) 
     App.vent.trigger "take:survey:button:clicked", survey 

     @show surveyView, region: @layout.surveyRegion 

    getLayoutView: -> 
     new List.Layout 

    getSurveyView: (surveys) -> 
     new List.Surveys 
     collection: surveys 

    bannerRegion: (surveys) -> 
     bannerView = @getBannerView surveys 

     @listenTo bannerView, "new:survey:clicked", -> 
     App.vent.trigger "new:survey", surveys 

     @show bannerView, region: @layout.bannerRegion 

    getBannerView: (surveys) -> 
     new List.Banner 
     collection: surveys 

그리고 링크가있는 바닥 글 템플릿 : 당신이 설명하는 것은 example.com/posts.json 브라우저의 역사에 대한 항목으로 추가 된 것처럼 소리를 만드는

<div class="container"> 
    <div class="row"> 
     <div class="col-sm-6 align-center"> 
     <a href="/privacy" id="footer-privacy-link">Privacy</a> 
     <a href="/contact">Contact us</a> 
     <div>©2014 Sample, LLC</div> 
     </div> 
     <div class="col-sm-4 align-center"> 
     <a class="facebook" href="https://www.facebook.com/sample"><i class="fa fa-facebook"></i></a> 
     <a class="twitter" href="https://twitter.com/sample"><i class="fa fa-twitter"></i></a> 
     <a class="email-link" href="/contact"><i class="fa fa-envelope"></i></a> 
     </div> 
    </div> 
</div> 
+0

문제의 코드를 보면 도움이 될 것입니다. – pdoherty926

답변

1

. 그러나 AJAX 호출은 일반적으로 기록에 추가되지 않으므로 잘못된 코드 router.navigate 또는 window.location = 또는 이와 비슷한 코드가 있어야합니다. 그러나 관련 코드를 보지 않고는 확실히 말할 수 없습니다.

+0

나는 많은 코드를 추가했지만, 실제로 그것을 보지 않고서는 아무것도 공개하지 않았다. 당신이 말하는 것은 의미가 있습니다, 나는 그것을 통해 계속 수색 할 것입니다 ... :) –

+0

그래, 나는 분명히 당신이 제공 한 코드에서 잘못된 것도 아무것도 보지 못합니다. 디버깅을 용이하게하기 위해 할 수있는 한 가지 방법은 백본 복사본을 열고'Backbone.history'의'navigate' 메소드를 찾으십시오 (라인 1469 라인은 다를 수 있지만 행 번호가 다를 수 있습니다). 그리고 나서'console .trace()'또는'debugger' 라인을 추가하면 코드가 호출 할 때마다 알 수 있습니다. 문제가 네비게이션 라인이 잘못되면, 그걸 찾는데 도움이 될 것입니다. 그렇지 않으면, 적어도'window.location ='또는 일부 수동 이력 조작 코드를 찾아야합니다. – machineghost

관련 문제