Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no way to implement the first example that you provided. You cannot implement the first example because there is no way to "delete" the browser history using Javascript.</p> <blockquote> <p>There is no way to clear the session history or to disable the back/forward navigation from unprivileged code. The closest available solution is the location.replace() method, which replaces the current item of the session history with the provided URL.</p> <p>- <a href="https://developer.mozilla.org/en/DOM/window.history" rel="noreferrer">https://developer.mozilla.org/en/DOM/window.history</a></p> </blockquote> <p>At best you can prevent the current page from being added to the browser history by using <code>window.location.replace</code> or <code>window.history.replaceState</code>. Backbone.js provides a convenient way of doing this by calling <code>router.navigate(fragment, [options])</code> on your router object and specifying <code>{replace: true}</code> in the options.</p> <p>Instead of relying on different routes to determine which view to display, I would try instead writing a master view which could handle showing/hiding the specific views.</p> <h2>EDIT</h2> <p>Ok, entering hacky territory...</p> <p>Since it seems that the "Category List" page is the page where history should be "reset", the solution I have posted attempts to solve both use cases you have mentioned. The code keeps track of a <code>historyState</code> variable, which represents when the "category-list" page is visitied as well as the other pages visited after it.</p> <pre><code>// in your application init... $(function(){ window.historyState = -1; router = new Backbone.Router({ routes: { "category-list": category-list, "category": category, "item": item } category-list: function(){ historyState = 0; }, category: function(){ if(historyState &gt;= 0) historyState++; }, item: function(){ if(historyState &gt;= 0) historyState++; } }); }); </code></pre> <ul> <li>If <code>historyState</code> is <code>-1</code> - we have not yet visited the "category-list" page.</li> <li>If <code>historyState</code> is <code>0</code> - we are currently on the "category-list" page.</li> <li>If <code>historyState</code> is greater <code>0</code> - number of pages visited since viewed "category-list" page.</li> </ul> <p>Now anytime a link is used to navigate to the "category-list" page, make sure it calls the following method to handle the appropriate navigation.</p> <pre><code>function routeToCategoryList(){ if( historyState &gt; 0 ){ // 'category-list' already exists in our history route to that page. window.history.go((historyState * -1)); } else { // otherwise, don't store an entry for the current page we are on. router.navigate("/category-list", {trigger: true, replace: true}); } } </code></pre> <p>If the 'category-list' page has already been visited go back in history the appropriate number of entries (this unfortunately keeps the other pages in the history, so you can still go forward to them). Otherwise if the 'category-list' page hasn't been visited yet navigate to it and be sure not to add the current page to the history.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload