问题描述:

This is my first attempt at Require.js and I'm trying to figure out how to use jQuery plugins with it, particularly history.js that should manage my SPA. Code below is located in main.js and the script runs but I can't figure how to actually use History.pushState(), State.getState() and other plugin methods. I keep getting "getState is not a function" error messages in the console.

(function() {

requirejs.config(

{

baseUrl: 'js',

paths: {

'jquery': 'vendor/jquery-1.11.2.min'

},

shim: {

'history': {

deps: ["jquery"],

exports: 'History'

}

},

map: {

'*': { 'jquery': 'jquery-private' },

'jquery-private': { 'jquery': 'jquery' }

}

}

);

define(["jquery"], function($) {

$(function() {

require(['history'], function( History ){

var

History = window.History,

State = History.getState();

});

});

});

})();

jquery-private contains this code:

define(['jquery'], function (jq) {

return jq.noConflict( true );

});

That's everything I've got so far as I'm only trying to figure stuff out and set up a document. I'm having some doubts about exports: History and function param in require(['history]) but it might be something else completely.

By the way, I've used history in a previous project so I feel like I understand how to use it, in case you might be wondering. :)

Thanks.

网友答案:

you are accessing history in code but path is not defined

           require(['history'], function( History ){

you need to add path of history js file like jquery.

    paths: {
        'jquery': 'vendor/jquery-1.11.2.min',
        'history' : '<path to js file>' 
    },
相关阅读:
Top