我遇到了 Agularjs 刷新返回 404 错误,该错误在过去几年中已有详细记录,但我仅在应用程序的一个页面上遇到此问题。除了我的用户信息页面之外,我有几个页面在刷新时都解析为它们的页面。这是我的路由代码。我已经包含了我的仪表板页面的路线(也有效)。
$locationProvider.html5Mode(true);
$stateProvider.
state("home", {
url: "/dashboard",
controller: "dashboardController as vm",
templateUrl: 'app/dashboard/view.html',
resolve: {
user: ['oauth',
function (oauth) {
return oauth.getOrLoadUser();
}]
}
}).
state("updateInfo", {
url: "/updateInfo",
controller: "updateInfoController as vm",
templateUrl: 'app/account/updateInfo.html',
resolve: {
user: ['oauth',
function (oauth) {
return oauth.getOrLoadUser();
}]
}
}).
正如您所看到的,我正在为我的 locationProvider 设置 Html5Mode,并且该路线与我的其他路线相同。 任何帮助将不胜感激。
更新 这是我的路线配置的样子。
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
Dictionary<string, string> handleInHome = new Dictionary<string, string>();
handleInHome.Add("login", "login/{*catchall}");
handleInHome.Add("dashboard", "dashboard/{*catchall}");
handleInHome.Add("aboutus", "aboutus/{*catchall}");
handleInHome.Add("requests", "requests/{*catchall}");
handleInHome.Add("faq", "faq/{*catchall}");
foreach (var key in handleInHome.Keys)
{
routes.MapRoute(
name: key,
url: handleInHome[key],
defaults: new { controller = "Home", action = "Index" }
);
}
routes.MapRoute(
name: "Default",
url: "{controller}/{action}/{id}",
defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
);
}
}
我尝试为帐户文件夹添加全部内容,但没有任何区别。 handleInHome.Add("account", "account/{*catchall}");
最佳答案
看来您需要在后端处理 /updateInfo
路由,以确保您为该路由提供 Angular 应用程序服务。
handleInHome.Add("updateInfo", "updateInfo/{*catchall}");
关于javascript - Angularjs 页面刷新仅在应用程序中的一个页面被破坏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48756702/