We are creating a single-page ASP.NET MVC application which uses AngularJS ui.router for client-side routing.
Currently, the back/forward buttons work as expected, but when the user clicks the browser's refresh button, the partial view is loaded without the layout page.
For example:
- User navigates to "http://localhost/MyApp/", MVC returns the layout page and then we navigate to the default state.
- User clicks on a link on the page and is navigated to that particular state via client side routing, url is now "http://localhost/MyApp/UserManagement/EditUser"
- User clicks on browser's refresh button, it loads the "UserManagement/EditUser" partial view without the layout
What else do we need to do in order for the layout to be reloaded when the user clicks the browser's refresh button?
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
var baseFrameworkApp = angular.module("BaseFrameworkApp", ['ui.router'])
.config(['$stateProvider', '$httpProvider', '$locationProvider', '$urlRouterProvider',
function ($stateProvider, $httpProvider, $locationProvider, $urlRouterProvider) {
$locationProvider.hashPrefix("!").html5Mode(true);
$urlRouterProvider.otherwise("/");
$stateProvider
.state('Default', {
url: '/{controller}/{action}',
views: {
"mainContainer": {
templateUrl: function (params) { return params.controller + '/' + params.action; }
}
}
});
}]);
<base href="/">
tag there. Also, you have to provide a catch-all url in your RouteConfig. All url requests without a#
goes to server, so server should map all urls to a single layout rendering action – v1p Jun 26 at 1:35