使用角度流星直接在地址栏上键入时路由不起作用

时间:2016-03-26 05:48:15

标签: meteor angular-ui-router 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');
    });

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

1 个答案:

答案 0 :(得分:0)

如果您使用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 href="/">

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

$locationProvider.html5Mode(true);