ui-sref link not working on ipad

2019-07-20 12:33发布

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:

Errormessage

1条回答
乱世女痞
2楼-- · 2019-07-20 13:03

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.

查看更多
登录 后发表回答