single-page-applicationdurandal-2.0durandal-navigation

How to go to a route without it being logged in browser history


I never want my logout route to show up the browser history. How can I configure the logout route to never log to the history. I know I can call activate(silent: true) but this doesn't solve my issue.

This is how I am setting up my routes:

activate: function () {
        app.init('shopper');

        router
            .makeRelative({ moduleId: "viewmodels", route: app.routes.routeBase })
            .map([
                { route: "logout", title: 'Log Out', moduleId: "logout/index", nav: true, hidden: app.auth.isGuest }
            ])
            .buildNavigationModel()
            .mapUnknownRoutes("errors/404")
            .activate({ pushState: true });
    }

Is there something I can pass in here that will cause the logout route to never be logged in the browser history? If not, what other options do I have to accomplish never logging the logout route in the browser history. Thanks.


Solution

  • There is no water proof way to avoid a page to appear in the history. But what you can do, is add a simple Javascript to throw you back (forward), once you hit that page.

    All you do is add this little script on the page that you shouldn't be able to navigate back to:

    <script language="JavaScript"><!--
        javascript:window.history.forward(1);
    //--></script>