azicchetti / jquerymobile-router

A router/controller for jquery mobile. Also adds support for client-side parameters in the hash part of the url. The routes handles regexp based routes. This plugin can be used alone or (better) with Backbone.js or Spine.js, because it's originally meant to replace their router with something integrated with jQM.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

No issue - design question

opened this issue · comments

My app is based on jQM, this router, backbone.js, require.js and runs on node.

The app routes and handlers reside all in one file. While the app is growing this file becomes quite huge. Is my approach the preferred design or is the a better way?

Hi,
a huge 'controller' file may be difficult to handle as you've noticed.
You can split its content across multiple files as you're probably doing with your views and models.

For instance, you can define a certain namespace:

App.Router

and add the functions you need, using either $.extend or simple assignments (App.Router.aCertainHandler=function(){... ).

The files containing your routes may be loaded in your index.html file with <script> tags, programmatically during the boot of your application, or 'on demand' when they're really needed.