从angularjs应用程序

时间:2015-11-26 12:09:31

标签: angularjs angular-ui-router

我使用了Removing the fragment identifier from AngularJS urls (# symbol)中建议的方式,我完成了以下更改:

在index.html页面

<head>
<base href="/">
</head>

在app.route.js

angular.config(configure);
  configure.$inject = ['$stateProvider', '$routeProvider', '$locationProvider'];
  function configure($stateProvider, $routeProvider, $locationProvider) {
    $locationProvider.html5Mode(true);
    $stateProvider
     .state('home', {
       url: '/',
       views: {
         'contentView': {
           templateUrl: 'app/modules/home/home.html',
           controller: 'HomeController as vm'
         }
       },
     })

 .state('login', {
        url: '/login',
        views: {
          'contentView': {
            templateUrl: 'app/modules/login/login.html',
            controller: 'LoginController as vm'
          }
        },
        data: { login: true }
      })

在Web.config文件中,我创建了一个如下所示的规则

<rule name="Main Rule" stopProcessing="true">
          <match url="^(.*)$" ignoreCase="false" />
          <conditions>
            <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />
          </conditions>
          <action type="Rewrite" url="/" />
        </rule>

如果不进行上述更改,我的网址就像 - http://localhost/projectname/#/ 但经过上述实施后,该网站未运行。任何人都可以建议我做错了什么

1 个答案:

答案 0 :(得分:0)

您的网址重写中缺少一些内容:

<rewrite>
      <rules>
        <rule name="My App Route" 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="^/(your APi path)" negate="true" />
          </conditions>
          <action type="Rewrite" url="/" />
        </rule>
      </rules>
    </rewrite>