简体   繁体   中英

Angularjs page refresh broken for only one page in app

I'm getting the Agularjs refresh returns 404 bug that has been well documented over the past few years, but I'm experiencing this issue on only one page in my app. I have several pages that all resolve to their pages on refresh except for my user info page. Here is the routing code I have for it. I have included the route for my dashboard page (which works) as well.

$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();
                    }]
            }
        }).

As you can see I'm setting Html5Mode on for my locationProvider, and the route is identical to my other routes. Any help would be much appreciated.

Update Here is what my routeConfig looks like.

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 }
        );
    }
}

I tried adding a catch all for the accounts folder, but I didn't make any difference. handleInHome.Add("account", "account/{*catchall}");

看起来您需要在后端处理/updateInfo路由,以确保为该路由提供Angular应用程序。

handleInHome.Add("updateInfo", "updateInfo/{*catchall}");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM