javascript - Angular.js : prettyPhoto URL redirected to default page mentioned in angular route

标签 javascript angularjs prettyphoto

当我单击与 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/

相关文章:

javascript - 无法加载图像。确保路径正确且图片存在

javascript - 谷歌应用脚​​本: Time Driven Triggers timezone issue

javascript - chrome/firefox- 如何运行 javascript 命令

javascript - 在 div 上使用 jquery append 方法附加一个 div

angularjs - 如何更改 ng-tags-input 分隔符? (默认 : dash)

javascript - 嵌套 HTML 表单替代方案

javascript - 从变量创建正则表达式的问题

javascript - Angular JS 是否有与 dojo.hitch() 等效的函数

javascript - 实现 prettyPhoto jQuery 插件

jQuery:PrettyPhoto API 不起作用