使url匹配'/''/索引'和'/index.html'到单一状态

Make url match '/', '/index' and '/index.html' to a single state

本文关键字:html 单一 index 状态 索引 url 匹配      更新时间:2023-09-26

我试图使以下url指向相同的状态,但只有两个可以工作。

  • http://path.com/✔
  • http://path.com/index✔
  • http://path.com/index.html✘

    $stateProvider
    .state('home', {
        url: '/{index}',
        controller: 'HomeController',
    });
    

在$stateProvider文档中,它表示url使用UrlMatcher模式,但没有图案似乎和我瞄准的手表相匹配。

那么,你如何使后者发挥作用呢?

谢谢!

/{index}并不是你想象的那样。它用参数{index}定义了/的状态。所以我非常确信它也会捕获例如/dummy

我认为您想使用/定义一个简单的状态,例如

$stateProvider.state('home', {
    url: '/',
    controller: 'HomeController',
});

然后使用ui路由器重定向(取自文档)

app.config(function($urlRouterProvider){   
    $urlRouterProvider.when('/index.html', '/');
    $urlRouterProvider.when('/index', '/');
})