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'
        });
}
]);
2
  • This is something that can be done server side only, which kind of server are you using ? (Apache / node.js...) Commented May 18, 2015 at 13:21
  • I am using IIS Express. Commented May 18, 2015 at 13:25

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Just in case : did you set the <base href="/"> in the document <head> (for html5Mode) ?
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.
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>

2 Comments

Put that in my web config. Still got localhost:10203/App/index.html, localhost:10203/App/index.html#/menu, 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.
application servererror, "Owin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f0ebd12fd5e55cc5" could not be found. The System cannot found the file error.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.