.NET MVC and Angular with ui-router

I have a scenario in which I use .NET MVC to serve the index.cshtml start page, which then provides all the Angular components needed to run the application with a single page. For routing, I use the excellent ui-router component with the Angular -UI command, and for the most part it works well.

My problem is loading the very first page. When viewed on a site, it does not go to the very first state / URL. It just loads my β€œshell” with no content. My application configuration code is as follows:

app.config(function ($stateProvider, $urlRouterProvider) {
    $urlRouterProvider.otherwise('/home');
    $stateProvider
        .state('home', {
            url: "/home",
            views: {
                "content": {
                    templateUrl: "app/dashboard/dashboard.html",
                    controller: 'DashboardController'
                },
                "subNav": {}
            },
        });

( ui-sref), . . , .NET MVC - , , , :

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

, , . , , .

?

+4
3

angular . , /, /home.

, URL- - ASP.Net MVC.

:

  • , /home
  • , DashboardController app.
  • app/dashboard/dashboard.html, , .
+1

, .

, run $stateChangeError.

app.run(['$rootScope','$state',function($rootScope,$state) {
    $state.transitionTo('home');

    $rootScope.$on('$stateChangeError', 
      function(event, toState, toParams, fromState, fromParams, error){ 
      $state.transitionTo('home');
    });
}]);
0

.net MVC . .net webApi api, .. ( ). Angular ui-router . -, . Angular SPA MVC. MVC, // .., Angular bower/grunt/gulp. , ... , , index.html ( Webapi, ). - ( MVC), index.html . Modern Web development, - .net vNext, npm/gulp/grunt/bower. Microsoft . vNext html/js/assets. vNext, MVC.

0
source

Source: https://habr.com/ru/post/1533880/


All Articles