本文介绍了router.js功能不执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Part of my main.js , i didnt use NEW because it gave issues saying it's not a function not sure if it's related to the error above

require(['app'], function(AppView){
    AppView.initialize();
});

I did a console.Log after Router.initialize(); at app.js , it can show. I also did a console log all the way above in this app router.js it's also showing, other than that , it doesnt show anything inside the function.

The console is only showing that 2 console Log (After Route.Initialize & Before router.js define

Any advice?I'm using http://backbonetutorials.com/organizing-backbone-using-modules/

My App.js

define([
    'jquery',
    'underscore',
    'backbone',
    'router', // Request router.js
], function($, _, Backbone, Router){
    var initialize = function(){
        // Pass in our Router module and call it's initialize function
        Router.initialize();
        console.log('Router Initialized');
    }

    return {
        initialize: initialize
    };
});
解决方案

Probably you're using a non-AMD version of Backbone.js and Underscore.js.

This way you've to add what it's called a "shim" to your main/config file.

As you can see this set dependencies and export your lib in order to let you using it in your scripts.

So, in your main/config file, after the paths try adding this shim part:

paths: {
    ...
},
shim: {
    'backbone': {
        deps: ['jquery','underscore'],
        exports: 'Backbone'
    }
}

Now I suppose you could proceed ...

这篇关于router.js功能不执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 17:10
查看更多