AngularJS URL';具有HTML5模式的s不';行不通
使用visual studio的AngularJS SPA模板。在我的app.js中,我有:AngularJS URL';具有HTML5模式的s不';行不通,html,angularjs,Html,Angularjs,使用visual studio的AngularJS SPA模板。在我的app.js中,我有: $stateProvider .state('touranalysis', { url: '/touranalysis', templateUrl: '/views/touranalysis/index', controller: 'tourAnalysisCtrl' }) $locationProvider.html5Mode(true)
$stateProvider
.state('touranalysis', {
url: '/touranalysis',
templateUrl: '/views/touranalysis/index',
controller: 'tourAnalysisCtrl'
})
$locationProvider.html5Mode(true);
如果我在本地运行,并点击我的链接进行touranalysis,它工作正常。这是我导航栏上的链接
<a href="~/touranalysis">Tour Analysis</a>
我点击F5,我得到一个页面未找到错误。我遗漏了什么?我猜您的服务器中没有touranalysis页面。“未找到页面”错误,因为当您单击F5时,浏览器请求查看分析页面。加载页面后,角度路由将起作用。如果我是正确的,您的模板使用的是ASP.NET MVC。因此,您可以添加如下自定义管线:
routes.MapRoute(
name: "touranalysis",
url: "touranalysis",
defaults: new { controller = "touranalysisController", action = "Index" });
这样ASP.NET MVC将加载touranalysisController的索引视图,该视图应包含ng视图。在此之后,Angularjs将加载/views/touranalysis/index
我希望这有帮助。如果您有任何问题,请告诉我。我对MVC和angularjs路由的混合感到困惑。实际上,我没有MVC控制器,只有用于所有服务器端处理(CRUD)的api控制器。为什么我需要在两个地方添加一条路线,并在他们什么都不做的情况下创建MVC控制器?我只是查看了angularJS SPA模板,它没有使用MVC routingOK,我还以为你在使用它,重点是你的浏览器正在寻找不存在的touranalysis页面。ASP.NET WEB API模板有一个视图文件夹,其中包含.schtml文件和包含RouteConfig.cs的App_Start文件夹。你的模板中有这些文件吗?您在哪里添加了ng视图?
routes.MapRoute(
name: "touranalysis",
url: "touranalysis",
defaults: new { controller = "touranalysisController", action = "Index" });