Reputation: 3915
I'm new to backboneJs.
Currently when i do browser refresh, it takes back me to login page.
var AppRouter = Backbone.Router.extend({
routes : {
// Pages
'startup' : 'LoginScreen',
'Home' : 'HomeScreen',
'AssetDetail':'AssetScreen',
'*actions' : 'LoginScreen'
},
...
});
var initialize = function(options) {
var appView = options.appView;
var router = new AppRouter(options);
router.on('route:LoginScreen', function(actions) {
require([ 'login/LoginView' ], function(StartView) {
console.log(" --route login");
var startView = new StartView();
});
});
router.on('route:HomeScreen', function(actions) {
require([ 'home/HomeView' ], function(HomeScreenView) {
console.log(" --route home");
var homeScreenView = new HomeScreenView();
});
});
router.on('route:AssetDetailScreen', function(actions) {
require([ 'views/AssetDetailView' ], function(AssetDetailScreenView) {
var assetdetailScreenView = new AssetDetailScreenView();
});
});
Backbone.history.start({pushState: true});
};
So lets say my current url is http://localhost:8080/myapp/# , and when i do browser refresh (F5 may be) , I want to load the same page.
How do I do it ?, Help me!
Upvotes: 1
Views: 927
Reputation: 7035
Not me who originally wrote this answer but I think it's the best solution.
*"You can call Backbone.history.loadUrl. To refresh the current page:
*`Backbone.history.loadUrl(Backbone.history.fragment);`*
Or as a link handler:
// Backbone.history.navigate
is sufficient for all Routers and will trigger the
// correct events. The Router's internal navigate
method calls this anyways.
var ret = Backbone.history.navigate(href, true);
// Typically Backbone's history/router will do nothing when trying to load the same URL. // But since we want it to re-fire the same route, we can detect // when Backbone.history.navigate did nothing, and force the route.
if (ret === undefined) {
Backbone.history.loadUrl(href);
}"*
Backbone: Refresh the same route path for twice
Upvotes: 1