需要解决MVC和Angular Routes

时间:2014-05-24 20:51:57

标签: angularjs asp.net-mvc-routing angularjs-routing

我有一个典型的MVC路由定义

 routes.MapRoute(
                name: "Default",
                url: "{controller}/{action}/{id}",
                defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
            );

App.js

(function () {
    'use strict';

    var app = angular.module('app', [

        //Angular modules
        'ngAnimate',     //animations
        'ngRoute',       //routing
        'ngSanitize'    //sanitize html bindings
    ]);

})();

并将角度路线定义为

  var app = angular.module('app');

    //collect the routes
    app.constant('routes', getRoutes());

    //config the routes and route resolvers
    app.config(['$routeProvider', 'routes', routeConfigurator]);

    function routeConfigurator($routeProvider, routes) {

        routes.forEach(function (r) {

            $routeProvider.when(r.url, r.config);
        });

        $routeProvider.otherwise({ redirectTo: '/' });
    }


    function getRoutes() {
        return [
            {
                url: '/',
                config: {
                    title: 'dashboard',
                    templateUrl: '/app/dashboard/dashboard.html',
                    settings: {
                        nav: 1,
                        content: '<i class="icon-home"></i><span class="hidden-tablet"> Dashboard</span>'
                    }
                }
            },
            {
                url: '/projects',
                config: {
                    title: 'projects',
                    templateUrl: '/app/project/project.html',
                    settings: {
                        nav: 2,
                        content: '<i class="icon-th"></i><span class="hidden-tablet"> Projects</span>'
                    }
                }
            },
            {
                url: '/project/new',
                config: {
                    title: 'project',
                    templateUrl: '/app/project/newProject.html',
                    settings: {}
                }
            }
        ];
    }

所以目前我的应用启动时,网址看起来像http://localhost:6722 它没有加载在角度路径配置中定义的第一条路线。只要我在/#/的网址末尾附加http://localhost:6722/#/,就会占用第一条路线。

请建议我需要做些什么来解决这个问题?

0 个答案:

没有答案