Benefits of using multiple routers?

I am starting to gradually build up my web application by adding routes and other routes to the router. An application is not a one-page application in the sense that it offers relatively independent functions.

For example, if you needed to create an application that included a wiki, a dashboard (and settings), and a game using wiki data, should you use only one router with many routes? or do you have to break the application into small subtasks with your own controllers?

In both cases, how to deal with the i18n problem? and loaded boot models (in the case of a single router)?

+6
source share
1 answer

Initially, I will say that it depends on your application architecture / functions and the scale of the websites you are going to make ...

Pros for a single routing file

  • It complies with the rule: easier - always - better , therefore, if you really do not need several routing files, just do not.
  • Multiple files can lead to conflict problems that can be resolved.
  • My personal experience, when I myself worked on a home web application, I saved only one file in the application directory.

But what about multiple routing files?

However, you can find the legitimate use of multiple routing files if you have different plugins for handling content types (wiki, dashboard, gallery ...), and if they automatically implement routes (which will not change from the website to another).

In this case, you can use a small file specifically for each plug-in, which will be automatically combined with the application routing file (Note: as I mentioned earlier, you might encounter route conflicts between files). In my home application, I use this solution to handle the backend panel (administrator), I "solved" the collision problem by reserving the "/ admin /" route for the backend, and then all plugin routes get a prefix with it.

Symfony example for PHP-Framework

Don't take the following as β€œyou should do it like this,” but you can see how it is done in Symfony here: http://www.symfony-project.org/book/1_2/09-Links-and-the-Routing- System

# default rules homepage: url: / param: { module: default, action: index } default_symfony: url: /symfony/:action/* param: { module: default } default_index: url: /:module param: { action: index } default: url: /:module/:action/* 

I18n

Do you want to translate the URL? If so, remember me a simpler statement. Do you really need this? I know this may give you some SEO optimizer, but I don’t think it would be worth compressing. In this case, you can use 1 file per language for each application.

PS: what do you mean by "loaded models (in the case of a single router)?"

+1
source

Source: https://habr.com/ru/post/894946/


All Articles