2

UPDATE

AngularJS works now. Switched to WebStorm IDE, but also had problem setting it up, that helped me: Bower "Git not in the PATH" error (Bower “Git not in the PATH” error).

Soon I will try ngrouting under WebStorm again.

How can I remove index.html from my localhost URL? There are similar questions, but they couldn't help me.

Here is what I did so far:

index.html:

<head><title>MyApp</title></head>    
<body>
  <div ng-view>
      <a href="#/menu">Menu</a>
      <a href="#/main">Main</a>
  </div>
</body>

app.js:

var app = angular.module('myApp', [
  'ngRoute',
  'ngResource',
  'HTML5ModeURLs'
});

config.js:

app.config(['$routeProvider', '$locationProvider',
function ($routeProvider, $locationProvider) {
    $route.html5Mode(true);

    $routeProvider.
        when('/menu', {
            templateUrl: 'Modules/Menu/view.html',
            controller: 'Modules/Menu/controller'
        }).
        when('/main', {
            templateUrl: 'Modules/Main/view.html',
            controller: 'Modules/Main/controller'
        }).
        otherwise({
            redirectTo: '/menu'
        });
}
]);
Community
  • 1
  • 1
AJ_83
  • 289
  • 1
  • 8
  • 22

2 Answers2

2

You try to remove index.html from your app url ?

app.config(['$routeProvider', '$locationProvider',
function ($routeProvider, $locationProvider) {
$route.html5Mode(true);

$routeProvider.
     when('/', {
        templateUrl: 'index.html',
        controller: 'HomeCtrl'
    }).
    when('/menu', {
        templateUrl: 'Modules/Menu/view.html',
        controller: 'Modules/Menu/controller'
    }).
    when('/main', {
        templateUrl: 'Modules/Main/view.html',
        controller: 'Modules/Main/controller'
    }).
    otherwise({
        redirectTo: '/menu'
    });
  }
]);

Setting the route '/' should do the job I guess. That's how I do it anyway.

enguerranws
  • 8,087
  • 8
  • 49
  • 97
  • Just in case : did you set the in the document (for html5Mode) ? – enguerranws May 19 '15 at 07:28
  • I set that. Seems like Visual Studio is not detecting AngularJS. (see my updated question). Of course I have ng-app="myApp" in the 'htm'l tag. – AJ_83 May 19 '15 at 12:31
2

You are using IIS Express to host your AngularJS application files, so I think this topic was what you were looking for. Yagiz Ozturk solution suggests you to configure your IIS server this way to rewrite URL, so you will be able to skip the index.html part :

<system.webServer>
<rewrite>
  <rules>
    <rule name="AngularJS" stopProcessing="true">
      <match url=".*" />
      <conditions logicalGrouping="MatchAll">
        <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
        <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
        <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
      </conditions>
      <action type="Rewrite" url="/" />
    </rule>
  </rules>
</rewrite>

Community
  • 1
  • 1
bviale
  • 5,245
  • 3
  • 28
  • 48
  • Put that in my web config. Still got http://localhost:10203/App/index.html, http://localhost:10203/App/index.html#/menu, http://localhost:10203/App/index.html#/main as url's. I also installed url rewriter for iis on server and added a base href to index.html. Getting a 'Owin' error, when I remove the # from the href's, but Microsoft.Web.Infrastructure is installed and references are made. – AJ_83 May 18 '15 at 14:08
  • application servererror, "Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5" could not be found. The System cannot found the file error. – AJ_83 May 18 '15 at 14:26