【问题标题】:Routes not working when directly typed on address bar with angular-meteor使用 angular-meteor 在地址栏上直接键入时路由不起作用
【发布时间】:2016-07-13 22:11:23
【问题描述】:

我正在研究 angular-meteor。我这样定义路线:

    angular.module('myapp').config(function($stateProvider, $urlRouterProvider, $locationProvider) {

        $locationProvider.html5Mode(true);
        $stateProvider
        .state('homepage', {

           url: '/homepage',
           template: '<mycomponent></mycomponent>'
        })

        .state('anotherpage', {

          url: '/other-route',
          template: '<othercomponent></othercomponent>'
        });
        $urlRouterProvider.otherwise('/homepage');
    });

在我直接在地址栏中直接输入 /other-route 的 url 之前,一切正常。浏览器只是回到 /homepage。提示?谢谢。

【问题讨论】:

  • &lt;other-component&gt;&lt;othercomponent 是两个不同的标签,后者是非法的。此外,您是否尝试过完全删除路线中的连字符
  • 你是对的,对不起。我刚刚重新编辑并尝试从路线中删除连字符,但没有任何变化。
  • 关闭html5Mode

标签: meteor angular-ui-router angular-meteor


【解决方案1】:

如果你使用 ASP.Net 那么你需要配置 global.asax 文件

private const string ROOT_DOCUMENT = "/Index.html";

protected void Application_BeginRequest(Object sender, EventArgs e)
{
  var path = Request.Url.AbsolutePath;


  string url = Request.Url.LocalPath;
  if (!System.IO.File.Exists(Context.Server.MapPath(url)))
    Context.RewritePath(ROOT_DOCUMENT);
}

index.html 也需要 base 标签

&lt;base href="/"&gt;

并将其添加到 app.config 部分的末尾

$locationProvider.html5Mode(true);

【讨论】:

  • ASP.net?我正在使用带有角度的 Meteor.js。
  • 尝试删除hmtl5模式并尝试带有#的directy URL,然后您将知道其HTML5模式是否相关。可能会缩小范围。
  • 感谢您的帮助。我刚刚尝试过,但即使关闭 HTML5 模式也没有任何变化。我只能从主页开始浏览路线。
  • 我上面解释的内容是为我做的,它的工作原理和你说的一样,但是如果我按 F5 或输入它就不起作用。我必须在根目录下对其进行排序,这解决了我的问题,因为您不使用 .net 我无法提供建议,但是您上面的代码是合理的,因为我使用了 web api,所以看看我放 $locationProvider.html5Mode(true) 的其他地方;最后但不确定这是否重要
猜你喜欢
  • 2016-01-10
  • 1970-01-01
  • 2020-01-26
  • 2020-11-05
  • 1970-01-01
  • 2017-02-03
  • 1970-01-01
  • 2017-08-17
  • 1970-01-01
相关资源
最近更新 更多