当我单击与 prettyPhoto
插件关联的任何图像时,浏览器的 URL 会更改为 example.com/#/prettyPhoto[residential1]/0/
并获取重定向到 .otherwise({..})
app.config(['$routeProvider', function ($routeProvider) {
$routeProvider
.when('/home', {
title: 'Home',
templateUrl: 'partials/home.html',
controller: 'PageCtrl'
})
.otherwise({
redirectTo: '/home'
});
}]);
我可以做下面提到的事情吗,例如:在 /prettyPhoto********
之后定义的任何内容都应该重定向到 /projects
:
.when('/prettyPhoto[*anyArray*]/*anyNumber*/', {
redirectTo: '/projects'
})
最佳答案
在文档中,它说:
Route path (matched against $location.path). If $location.path contains redundant trailing slash or is missing one, the route will still match and the $location.path will be updated to add or drop the trailing slash to exactly match the route definition.
Path can contain named groups starting with a colon: e.g. :name. All characters up to the next slash are matched and stored in $routeParams under the given name when the route matches. path can contain named groups starting with a colon and ending with a star: e.g.:name*. All characters are eagerly stored in $routeParams under the given name when the route matches. path can contain optional named groups with a question mark: e.g.:name?.
For example, routes like /color/:color/largecode/:largecode*/edit will match /color/brown/largecode/code/with/slashes/edit and extract:
所以如果我使用它所说的,你的代码就会变成:
.when('/prettyPhoto:anyArray/:anyNumber', {
redirectTo: '/projects'
})
文档:https://docs.angularjs.org/api/ngRoute/provider/ $routeProvider
希望我的回答适合您:)
关于javascript - Angular.js : prettyPhoto URL redirected to default page mentioned in angular route,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26608235/