【问题标题】:$urlRouterProvider.otherwise('/'); conflicting with Mean-seo$urlRouterProvider.otherwise('/');与 Mean-seo 冲突
【发布时间】:2015-10-23 14:01:35
【问题描述】:

我正在尝试实现 Mean-seo,它似乎在工作,除了每次重定向到主页时。

http://localhost:3333/?_escaped_fragment_=/contact-us 闪现联系我们页面,然后重定向到主页。

如果我删除

$urlRouterProvider.otherwise('/');

它显示了联系我们页面,但主页只是空白。

【问题讨论】:

  • 不确定如何生成该网址。爬虫会查看?_escaped_fragment_=/contact-us。假设您有适当的元标记,他们会在 ! 之后获取所有内容
  • 对不起,你是对的,我在最后删除了一个额外的 #!/。
  • 当你说正确的元标签时,我假设你指的是<meta name="fragment" content="!">
  • 是的,关于元,但它们还包括第一个 /,您也没有显示。 Angular 还将领先的 / 放在默认页面上。那么当_escaped_fragment_ 值只是斜线后端应该服务于主页时
  • 试过了。现在是<meta name="fragment" content="!/">,但它仍然在末尾添加#!/并转到主页

标签: angularjs angular-ui-router mean meanjs


【解决方案1】:

这似乎解决了我的问题。使用这个

    $urlRouterProvider.otherwise(function ($injector, $location) {
       //what this function returns will be set as the $location.url
        var path = $location.absUrl();
        if (path.indexOf('_escaped_fragment_') === -1) {
            //instead of returning a new url string, I'll just change the $location.path directly so I don't have to worry about constructing a new url string and so a new state change is not triggered
            return '/';
        }
        // because we've returned nothing, no state change occurs
    });

而不是

$urlRouterProvider.otherwise('/');

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-04-29
    • 1970-01-01
    • 2023-03-14
    • 2017-12-09
    • 2013-10-21
    • 2020-08-19
    • 2010-12-10
    相关资源
    最近更新 更多