2016-11-23 2 views
0

내 템플릿이 내 SPA에 표시되는 데 문제가 있습니다. 모든 스크립트는 오류없이 실행되며 브라우저를 통해 내 HTML 템플릿을 탐색 할 수 있지만 각도는 내 경로 구성을 내 애플리케이션에 연결할 수 없습니다.AngularJS 라우팅을 사용하는 ASP.NET 코어

(function(angular) { 
    'use strict'; 

    var app = angular.module('over_the_counter', [ 
     'ngRoute' 
    ]); 

    app.run(function() { 
    }); 

    app.config(['$routeProvider', 
     function ($routeProvider) { 
      $routeProvider. 
       when('/', { 
        templateUrl: 'app/landing/landing.html', 
        controller: 'LandingController', 
        controllerAs: 'ctrl' 
       }). 
       otherwise({ 
        redirectTo: '/' 
       }); 
     } 
    ]); 
}(window.angular)); 

http://localhost:55907/app/landing/landing.html으로 이동하면 페이지가 렌더링됩니다. HTML 파일은 wwwroot 폴더에 있습니다.

+0

당신이 컨트롤러 소스와 함께 제공 할 수있는 당신은 당신의 연결을 어디? 이 코드는 각도 적용 및 경로 초기화를 수행합니다. –

+0

@ GrayFox 왜 컨트롤러 소스를 볼 필요가 있습니까? 내 경로 제공 업체가 초기화 중에 내 경로를 구축 중입니다. – bdparrish

+0

나는 당신을 오해했습니다. 그래서, 내가 제대로 이해한다면, 당신의 페이지는'http : // localhost : 55907 /'url에서 작동하지 않는 것입니까? –

답변

0
당신이 startup.cs 파일에 코드의 appsettings.json하거나이 라인에 더 많은 구성을 추가 할 필요가

:

DefaultFilesOptions options = new DefaultFilesOptions(); 
      options.DefaultFileNames.Clear(); 
      options.DefaultFileNames.Add("Index.html"); 
      app.Use(async (context, next) => 
      { 
       await next(); 

       if (context.Response.StatusCode == 404 && !Path.HasExtension(context.Request.Path.Value)) 
       { 
        context.Request.Path = "/Index.html"; 
        await next(); 
       } 
      }) 
      .UseCors("AllowAll") 
      .UseDefaultFiles(options) 
      .UseStaticFiles() 
      .UseIdentity() 
      .UseMvc(); 
관련 문제