相关疑难解决方法(0)

如何在HTML5模式下为URL重写AngularJS应用程序配置IIS?

我有AngularJS种子项目,我已经添加了

$locationProvider.html5Mode(true).hashPrefix('!');
Run Code Online (Sandbox Code Playgroud)

到app.js文件.我想配置IIS 7以将所有请求路由到

http://localhost/app/index.html
Run Code Online (Sandbox Code Playgroud)

这对我有用.我该怎么做呢?

更新:

我刚刚发现,下载并安装了IIS URL Rewrite模块,希望这样可以轻松,明显地实现我的目标.

更新2:

我想这总结了我想要实现的目标(取自AngularJS Developer文档):

使用此模式需要在服务器端重写URL,基本上您必须重写所有链接到应用程序的入口点(例如index.html)

更新3:

我还在努力,我意识到我不需要重定向(有重写规则)某些URL,例如

http://localhost/app/lib/angular/angular.js
http://localhost/app/partials/partial1.html
Run Code Online (Sandbox Code Playgroud)

所以css,js,lib或partials目录中的任何内容都不会被重定向.其他所有内容都需要重定向到app/index.html

任何人都知道如何轻松实现这一点,而无需为每个文件添加规则?

更新4:

我在IIS URL重写模块中定义了2个入站规则.第一条规则是:

IIS URL重写入站规则1

第二条规则是:

IIS URL重写入站规则2

现在,当我导航到localhost/app/view1时,它会加载页面,但是支持文件(css,js,lib和partials目录中的文件)也被重写到app/index.html页面 - 所以一切都将到来无论使用什么URL,都返回index.html页面.我想这意味着我的第一条规则,即应该阻止这些网址被第二条规则处理,不起作用..任何想法?...任何人?...我感觉很孤单... :-(

iis url-rewriting angularjs

136
推荐指数
4
解决办法
11万
查看次数

使用angular.js路线手动刷新时仍然会"找不到"

在Angular.js路由上阅读了大量的报告和stackoverflow问题之后,当我进行手动刷新时,我仍然收到"未找到"错误.

脚步:

  1. 浏览到localhost- >因为我的配置(下面),我被带到了localhost/home.视图和一切都很好.
  2. 在浏览器中点击刷新 - >浏览器显示此信息 Not Found: the requested /home is not found on this server

这个问题可能最像刷新页面给出"找不到页面"

我的配置

// Routing configuration.
angular.module('myModule')
    .config(['$routeProvider', '$locationProvider', 
    function ($routeProvider, $locationProvider) {
        // Enable pushState in routes.
        $locationProvider.html5Mode(true);

        $routeProvider
            .when('/home', {
                templates: {
                    layout: '/views/home.html'
                },
                title: 'Welcome!'

            })
            .when('/launchpad', {
                templates: {
                    layout: '/views/layouts/default.html',
                    content: '/views/partials/profile.html'
                },
                title: "Launchpad"
            })
            .otherwise({
                redirectTo: '/home'
            });

    }
]);
Run Code Online (Sandbox Code Playgroud)

我做过的其他事情:

  • 在我index.html,我已经有了<base href="/">
  • 升级到角度1.2.1

这是我尝试过的htaccess规则.没有工作.

刷新页面给出"找不到页面" …

javascript .htaccess angularjs angular-routing

10
推荐指数
2
解决办法
1万
查看次数