0

I want to create page navigation for my app written in Backbone.

when I want to create the page navigation, I'm having problem with creating the URL.

<a href="' + Backbone.history.fragment + '/some_page_number">some_page_number</a>

because Backbone.history.fragment will return path/to/1

the code above will return path/to/1/some_page_number.

while I want it to be

path/to/some_page_number.

how can I make it so.

Thanks in advance.

bbnn
  • 3,505
  • 10
  • 50
  • 68

1 Answers1

1

My suggestion:

<a href="' + MyApp.Utils.linkToPage( some_page_number ) + '">some_page_number</a>

// code no tested
MyApp.Utils.linkToPage = function( page ) {
  return Backbone.history.fragment.replace( /\/\d*$/, "" ) + "/" + page;
}

Maybe the RegExp is not properly defined but you can make an idea.

fguillen
  • 36,125
  • 23
  • 149
  • 210