سؤال

When using the code below and entering the address index.html#players I am not taken to the players route, in fact nothing happens at all. However, if I open up the dev tools and run Parse.history.checkUrl() it works as expected. When I remove Parse.history.start() and do it manually I get TypeError: undefined is not a function.

$(() ->
    $wrapper = $('#wrapper')

    Router = Parse.Router.extend({
        routes: {
            'selected': 'selected'
            'players': 'players'
            '': 'teams'
        }

        selected: () ->
            console.log('selected')
            $wrapper.removeClass()
            $wrapper.addClass('selected')

        players: () ->
            console.log('players')
            $wrapper.removeClass()
            $wrapper.addClass('players')

        teams: () ->
            console.log('teams')
            $wrapper.removeClass()
            $wrapper.addClass('teams')
    })

    window.router = new Router()
    Parse.history.start()
)
هل كانت مفيدة؟

المحلول

If anyone else is having this problem and urgently needs a work-around I have found that the code below works.

window.router = new Router()
try
    Parse.history.start({})
catch err
    console.log(err)
Parse.history.checkUrl()
window.onhashchange = Parse.history.checkUrl
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top