没有哈希角直接URL [英] Angular Direct Url without hash

查看:100
本文介绍了没有哈希角直接URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有建立在MVC和C#.NET,工作正常的站点,现在我想建立采用了棱角分明的同一个移动网站,所以我想在URL中没有哈希所以我用下面的code在我的js文件

I have a site that i built on mvc and c#.net which works fine, now i am trying to build mobile site for the same using angular, so i want the urls to be without hash so i use the following code in my js file

var app = angular.module('mobilesite', ["ngRoute", "ngTouch", "mobile-angular-ui", "shoppinpal.mobile-menu"]);

app.config(['$httpProvider', function ($httpProvider) {
    $httpProvider.defaults.headers.common["X-Requested-With"] = 'XMLHttpRequest';
}]);

app.config(function ($routeProvider, $locationProvider) {
    $routeProvider
        .when('/Blog', {
        templateUrl: "/Blog/Index"
    });

    //$locationProvider.html5Mode(true);
});

app.controller('maincontroller', function ($scope) {
    $scope.Name = "Index Mobile";
});

app.controller('blogcontroller', function ($scope) {
    $scope.Name = "Blog Mobile";
});

例如网址博客将的http://本地主机/博客并点击时没有问题的作品完美链接。

for example the url for blog will http://localhost/Blog and it works perfectly with no issues when clicked on the link.

但是,当我打开一个新的浏览器并输入上述网址直接我没有得到任何布局加载,只是它显示{{名}}。当我改变了JavaScript才能使用散列然后一切完美的作品。

But when i open a new browser and type the above url directly i get no layout loaded and only it displays {{Name}}. When i changed the javascript to use hash then everything works perfectly.

我失去了一些东西在这里,请帮助。

Am i missing something here, please help.

推荐答案

感谢您的答复,但INFACT我使用MVC 4.0和我固定它两个方面,首先我必须从正规的网站的web.config URL重写逻辑,因为这是移动,我不想不同的URL,所以尽管我做了我html5mode为true,它不工作,所以我改变routeprovider条件小写和触发。

Thank you for the reply but infact i was using mvc 4.0 and i fixed it two ways, first i have web.config url rewrite logic from regular site, and since this is mobile i dont want different urls, so even though i made my html5mode to true, it is not working, so i changed routeprovider condition to lower case and that triggered.

 <rewrite>
  <rules>
    <rule name="Add WWW prefix">
      <match url="(.*)" ignoreCase="true"></match>
      <conditions>
        <add input="{HTTP_HOST}" pattern="^xxxxx\.com"/>
      </conditions>
      <action type="Redirect" url="http://www.xxxxxx.com/{R:1}" redirectType="Permanent"/>
    </rule>
    <rule name="Lower Case URLs" stopProcessing="true">
      <match url="[A-Z]" ignoreCase="false" />
      <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{URL}" pattern="WebResource.axd" negate="true" />
      </conditions>
      <action type="Redirect" url="{ToLower:{URL}}" />
    </rule>
  </rules>
</rewrite>

但是当我刷新页面或访问它直接我是在布局检查是否request.isajaxrequest并做了魔力。

but when i refreshed the page or accessing it directly i was checking on layout if the request.isajaxrequest and that did the magic.

这篇关于没有哈希角直接URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆