使用 angular 路由重新加载页面时出现错误 404

Error 404 on page reload with angular routing

我在重新加载页面时收到错误 404。这发生在用户在 ng-view 中加载新模板后(从路由重定向)。 路由是这样配置的。

config(["$routeProvider", "$locationProvider", function ($routeProvider, $locationProvider) {
        $routeProvider
            .when('/', {
                templateUrl: '/templates/home.html',
                controller: 'smu72Controller'
            })
            .when('/objects', {
                templateUrl: '/templates/objects.html',
                controller: 'smu72Controller'
            })
            .when('/object/:Id', {
                templateUrl: '/templates/object.html',
                controller: 'smu72Controller'
            })
        .otherwise({
            redirectTo: "/"
        });
        $locationProvider.html5Mode(true);
    }

Global.asax中重写url解决的问题如下:

protected void Application_BeginRequest(Object sender, EventArgs e)
    {
            string url = Request.Url.LocalPath;
            if (!url.Contains("api") && !System.IO.File.Exists(Context.Server.MapPath(url)))
                Context.RewritePath(ROOT_DOCUMENT);
    }