How routing works in javascript MVC frameworks

Most JavaScript MVC frameworks require you to separate application files from these directives:

-App -Controllers -Models -Views 

I create my own MVC framework in the hope that it will help me better understand the concepts before I continue to use one of the well-established frameworks.

My question is, how do existing structures create this directory structure? How does the controller know that the view is in the directory and in the views folder, for example? How did this message become possible?

I searched google for routing in MVC Javascript. I see that the routing URL indicates the controller that will be called, and the parameters that will be sent to this controller, but this does not explain what I need to know.

+4
source share
1 answer

JS MVC structures do not have a directory structure. You can dynamically load MVC components from directories, but this method is quite complicated.

Now I have the same problem with a big RIA. I use the Backbone framework , and I organized the directory structure myself (my structure looks exactly like yours). Then I included all the JS files in my HTML template. But for production mode, I merge all my JS files, and I put all parts of MVC into one file.

At first I tried to dynamically load part of MVC from the router, but I had a lot of problems with the loader for dependencies between models, controllers and views. It may also slow down your code.

So it is best to download all the js files you need at once, or use Require.js .

0
source

All Articles