MVC 6 Catch-all路由与ui.router

时间:2016-06-16 09:49:05

标签: angularjs angular-ui-router asp.net-core-mvc

我测试了一个新的AspNetCore MVC 6设置,我遇到了一个全能路线的问题。服务器设置为使用“http://localhost:5000/”和全能路由。转到“http://localhost:5000/asdasd”工作正常,但“http://localhost:5000/asdasd/”失败并显示错误。

在_layout.cshtml中设置基本href:
    <script> document.write('<base href="' + document.location + '" />'); </script>

在我的创业公司中使用它:

app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "catchall",
                template: "{*url}",
                defaults: new { controller = "Home", action = "Index" });
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");
        });

这在我的routing.ts中:

module app {
export class RoutingConfig {
    static $inject = ["$locationProvider", "$stateProvider", "$urlRouterProvider"];
    private ViewLocation: string = "assets/views/";

    constructor(private $locationProvider: ng.ILocationProvider,
        private $stateProvider: ng.ui.IStateProvider,
        private $urlRouterProvider: ng.ui.IUrlRouterProvider
    ) {

        $urlRouterProvider.otherwise("/");
        $locationProvider.html5Mode(true);

        $stateProvider.state("home", <ng.ui.IState>{
            cache: false,
            url: "/",
            templateUrl: this.ViewLocation + "home/home.html",
            controller: HomeController.ControllerId,
            controllerAs: "vm"
        });
    }
}

angular.module("app").config(RoutingConfig);
}

1 个答案:

答案 0 :(得分:1)

在修好下面的路线后,我无法重复你所看到的内容:

<强>路线:

app.UseMvc(routes =>
        {
            routes.MapRoute(
                name: "default",
                template: "{controller=Home}/{action=Index}/{id?}");

            routes.MapRoute(
                name: "catchall",
                template: "{*url}",
                defaults: new { controller = "Home", action = "CatchAll" });
        });

动作:

public string CatchAll(string url)
{
    return $"CatchAll:{url}";
}