Rohit Sharma
Rohit Sharma

Reputation: 41

How to reuse router object on another html page in Backbone JS?

I am fairly new to Backbone JS and still figuring out its nuances.

I have created a router class in main.js which is included in index.html. Also, I have created an object of that router class associated to same html page.

Now, if I redirect to next html page all the created objects get lost. Even if I associate it to window object, it also get lost on a page redirect.

So, my question is how do I reuse my router object on next html page without storing it in sessionStorage or localStorage?

Should I always include the router js file on each html page and create a new object every time? Is there any other way to achieve what I am trying to do? Please enlighten me.

Upvotes: 0

Views: 166

Answers (1)

T J
T J

Reputation: 43166

Backbone.js is primarily designed to create SPAs (single Page Applications) especially the routing which is based on the hash change events by default.

For some reason if you must have actual redirection between HTML pages, then considered each as separate applications, i.e both should load the libraries, setup their own backbone components etc. Data can be shared between them using client side solutions like localStorage or REST API.

Upvotes: 0

Related Questions