backbone.marionette.subrouter icon indicating copy to clipboard operation
backbone.marionette.subrouter copied to clipboard

using back button does not re-trigger all my routes

Open newtonianb opened this issue 9 years ago • 1 comments

Situation: Loading the page from the URL triggers all my routes and subroutes but accessing that URL after pressing the back or forward button only triggers the last subroute.

Problem Let's say I access http://host/path1/path2/path3 from within he App I click on a link which brings me to http://host/otherpath. When I press the back button it brings me back to http://host/path1/path2/path3 in the URL but only my ModuleThree.Router gets hit. I want all of them to get hit again, how can I do this?

  1. user loads url http://host/path1/path2/path3
inside one
inside two
inside three
  1. user clicks on link that goes to http://otherpath
  2. user presses back button
inside three

My problem is on step 3, I'm expecting all the subroutes to re-trigger for my app to function correctly but only the last sub-route is triggered.

Example: Below I setup my subrouters so when accessing http://host/path1/path2/path3 I have 3 matches triggered total

/path1/*subroute handled by ModuleOne.Router (initialized by appInitiliazer) /path2/*subroute handled by ModuleTwo.Router (initialized by ModuleOne.Router) /path3/*subroute handled by ModuleThree.Router (initialized by ModuleTwo.Router)

  ## ROUTER
  class ModuleOne.Router extends Marionette.AppRouter
    routes:
      "path1/*subroute" : "pathOne"
    pathOne: (hash) ->
      console.log 'inside one'
      ## this gets triggered on URL enter if /path1 is in URL
      new App.ModuleTwo.Router("path1")

  App.addInitializer ->
    new ModuleOne.Router

## -------------------------------------------------------

  ## ROUTER
  API_ROUTER = 
    pathTwo: ->
      console.log 'inside two'
      new App.ModuleThree.Router("path1/path2")
  class ModuleTwo.Router extends Marionette.SubRouter
    controller: API_ROUTER
    appRoutes:
      "path2/*subroute" : "pathTwo"

## -------------------------------------------------------
  ## ROUTER
  API_ROUTER = 
    pathThree: ->
      console.log 'inside three'
  class ModuleThree.Router extends Marionette.SubRouter
    controller: API_ROUTER
    appRoutes:
      "path3/*subroute" : "pathThree"  

newtonianb avatar Mar 07 '15 21:03 newtonianb

Sorry for the late reply @newtonianb. I unfortunately do not have the time right now to jump back into the Backbone Marionette world and figure out a solution. If you however want to poke around the code and submit a pull request I would be more than happy to merge it in. Apologies

pushchris avatar Mar 15 '15 23:03 pushchris