ui-sref link not working on ipad

隐身守侯 提交于 2019-12-12 17:44:56

问题


My (phonegap) application is working fine in my browser (Chrome+Ripple) as well on my android tablet. However the link isn't working anymore when build the app with xCode and run it on the iPad.

$rootScope.$on('$stateChangeError', function(){..});

shows an error:

config: Object
data: ""
headers: function (c) {a||(a=vc(b));return c?a[D(c)]||null:a;}
status: 404
statusText: ""
__proto__: Object

I guess 404 means "state not found"?

Route:

.state('seminar', {
    url: "/seminar/{id}",
    views: {
        'nav@':  { templateUrl: "views/navigation/main.html" },
        'main@': { templateUrl: "views/seminars/main.html" },
        'side@': { templateUrl: "views/seminars/side.html" }
    }
})

View:

<a href ui-sref="seminar({ id: seminarCtrl.seminar.id})">Start</a>

On the login-form,

ng-submit()

is working fine.

I couldn't find any other questions related to this problem. Could there be a problem with iOS and ui-sref/ui-router?

Thank you in advance.

-- Update 1 --

Here is a screenshot of the error message thrown by the $stateChangeError function:


回答1:


I couldn't find an answer why it is working in the browser but not on iOS, but i managed to find a solution.

My new router:

.state('seminar', {
        url: "/seminar/{seminar_id}",
        views: {
            'nav@':  { templateUrl: "views/navigation/main.html" },
            'main@': { templateUrl: "views/seminars/main.html" },
            'side@': { templateUrl: "views/contact/side.html" }
        }
    })
    .state('seminar.course', {
        url: "/course/{course_id}",
        views: {
            'main@': { templateUrl: "views/courses/main.html" },
            'side@': { templateUrl: "views/courses/side.html" }
        }
    })

The problem was hidden in the second route. At first I had written

url: "seminar/{seminar_id}/course/{course_id}",

which lead to a wrong url

/seminar/1/seminar/1/course/5

It worked for iOS after removing the first part of the url.

Also to mention, the seminar_id will be handed to the second route automatically and is available in the $stateParams.

Hopefully someone can use this information.



来源:https://stackoverflow.com/questions/27521433/ui-sref-link-not-working-on-ipad

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!