【问题标题】:URL in web api and angularjsWeb api 和 angularjs 中的 URL
【发布时间】:2014-05-06 00:04:49
【问题描述】:

在 Visual Studio 2013 中,我设置了一个 web api 项目并添加了一个带有 angularjs 框架的 index.html 页面:为什么,当我运行项目时,url 是

http://localhost:49375/index.html#/

如何删除根页面的 index.hmtl#?

在 angularjs 我有以下路线:

gestionale.config(['$routeProvider',
  function ($routeProvider) {
  $routeProvider.
    when('/', {
        templateUrl: 'View/people.html',
        controller: 'mainController'
   });
}]);

并在 WebApiConfig.cs 中:

config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

【问题讨论】:

    标签: html asp.net-mvc angularjs asp.net-web-api


    【解决方案1】:

    我想你指的是:

    $locationProvider.html5Mode(true);
    

    它是这样使用的:

    angular.module('demoApp',['ngRoute'],function ($routeProvider, $locationProvider)
    {
        $locationProvider.html5Mode(true);
    
        $routeProvider.
            when('/',{
    ...
    

    它基本上允许您使用不带# 前缀字符的角度路由。

    【讨论】:

    • 他还需要设置一些“匹配所有”服务器端路由指向引导视图或使用 IIS UrlRewrite...否则当他开始收到 404 错误时他会感到失望:)跨度>
    猜你喜欢
    • 2014-08-03
    • 1970-01-01
    • 2015-07-22
    • 1970-01-01
    • 1970-01-01
    • 2014-11-11
    • 1970-01-01
    • 2014-02-25
    • 2014-10-21
    相关资源
    最近更新 更多