AngularJSとC#(API用)を使用してASP.NET Core SPAを作成していますが、ページの更新に関して少し問題があります。ブラウザのページのリロードが機能しない
たとえば、2つのリンクを持つホームページがあります。これらのリンクは次のとおりです。 - ホーム(にリダイレクト:/ホーム) - クライアント(にリダイレクト:/クライアント)
の問題は、私は/クライアントルート上だと私は私のページ(F5)を更新すると、あります再読み込み後、私はページをリロードする前と同じビューを持っているはずです。
私のコードがあります:
app.js
var app = null;
(function() {
'use strict';
appConfig.$inject = ['$routeProvider', '$locationProvider'];
app = angular.module('app', [
'ngRoute',
'ngResource'
]);
app.config(appConfig);
function appConfig($routeProvider, $locationProvider) {
// Define the routes
$routeProvider
.when('/', {
templateUrl: '/views/home.html',
controller: 'homeController',
title: 'Home'
})
.when('/clients', {
templateUrl: '/views/clients.html',
controller: 'clientsController',
title: 'Clients'
})
.when('/clients/add', {
templateUrl: '/views/addClient.html',
controller: 'addClientController',
title: 'Add new client'
})
.when('/404', {
templateUrl: '/views/404.html',
title: '404 Not found'
})
.otherwise({
redirectTo: '/404'
});
$locationProvider.html5Mode(true);
}
app.run(['$rootScope', '$route', function ($rootScope, $route) {
$rootScope.$on('$routeChangeSuccess', function() {
document.title = 'Blume - ' + $route.current.title;
});
}]);
})();
clientController.js
(function() {
'use strict';
angular
.module('app')
.controller('clientsController', clientsController);
clientsController.$inject = ['$location', '$scope', '$resource', 'clientService'];
function clientsController($location, $scope, $resource, clientService) {
$scope.clients = clientService.query();
}
})();
clientService.js
(function() {
'use strict';
angular
.module('app')
.factory('clientService', clientService);
clientService.$inject = ['$resource'];
function clientService($resource) {
return $resource('/api/client/:id');
}
})();
web.configファイル
は<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<rewrite>
<rules>
<!--Redirect selected traffic to index-->
<rule name="Index Rule" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_URI}" matchType="Pattern" pattern="^/api/" negate="true" />
</conditions>
<action type="Rewrite" url="/index.html" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
によって実行すべきですか? – charlietfl
投稿を編集してweb.configファイルを追加しました。私はチュートリアルに続き、web.configをコピー/ペーストしました。多分私のエラーはそこからです:/ – Eastrall
また、 "以前と同じように見えるはずのもの"を明確にしていません。*具体的に、または実際に何が起きているのか – charlietfl