我开始逐步构建我的 Web 应用程序,向路由器添加路由和其他路由。该应用程序不是单页应用程序,因为它提供了相对独立的功能。
例如,如果您必须构建一个包括 wiki、仪表板(和设置)的应用程序以及使用 wiki 数据的游戏,您是否应该仅使用一个具有多个路由的路由器?或者您应该将应用程序拆分为具有自己的控制器的小型子应用程序?
这两种情况下,如何处理i18n的问题呢?并加载引导模型(如果是单个路由器)?
I am starting to build my web application progressively, adding routes and other routes to the router. The application is not a single page application, in the sense that it offers relatively independent features.
For example, if you had to build an application including a wiki, a dashboard (and settings), as well as a game using the wiki's data, should you use only one router with many routes? or should you split the application into small sub-applications with their own controllers?
In both cases, how to handle the problem of i18n? and loaded bootstrapped models (in case of a single router)?
发布评论
评论(1)
最初,我会说这取决于您的应用程序架构/功能以及您要做的网站的规模...
单个路由文件的优点
但是多个路由文件呢?
但是,如果您有不同的插件来处理内容类型(wiki、仪表板、图库...),并且它们自动实现路由(不会从一个网站更改为另一个网站),那么您可以找到多个路由文件的合法用法。
在这种情况下,您可以专门为每个插件使用小文件,这些插件将自动合并到应用程序路由文件(注意:正如我之前提到的,通过这样做,您可能会遇到文件之间的路由冲突)。
在我的自制应用程序中,我使用此解决方案来处理后端(管理)面板,我通过为后端保留“/admin/”路由来“解决”冲突问题,然后所有插件的路由都以它为前缀。
PHP-Framework Symfony 示例
不要将以下内容视为“您应该这样做”,但您可以在此处查看 Symfony 中的操作方式:http://www.symfony-project.org/book/1_2/09-Links-and-the-Routing-System
I18n
您愿意翻译网址吗?
如果是的话,请记住我的“越简单越好”的说法。你真的需要它吗?我知道它可能会给你一些搜索引擎优化提升,但我认为这不值得挤压。
在这种情况下,您可以为每个应用程序的每种语言使用 1 个文件。
PS:“引导模型(如果是单个路由器)”是什么意思?
Originally, I'll say it depends on your application architecture/features and the scale of websites you are going to do...
Pros for a single routing file
But what about multiple routing file?
You could however find a legitimate usage to multiple routing files if you have different plugins to handle content-types (wiki, dashboard, gallery...), and if they automatically implement routes (that won't change from a website to another).
In this case you could use small file specifically for each plugins that will be automatically merged to the app routing file (Note: as I previously mentionned, by doing this you could experience route collisions between files).
In my homemade app, I'm using this solution to handle the backend (admin) panel, I "solved" the collision problem, by reserving the "/admin/" route for the backend then all plugin's routes get prefixed with it.
The PHP-Framework Symfony example
Don't take the following as a "you should do it like this" but you can look how it's done in Symfony here: http://www.symfony-project.org/book/1_2/09-Links-and-the-Routing-System
I18n
Are you willing to translate urls ?
If yes, remember me simpler-is-better statement. Do you really need it ? I'm aware that it may grant you some SEO boost, but I don't think it would be worth the squeeze.
In this case, you could use 1 file per language, per app.
PS: what do you mean by "bootstrapped models (in case of a single router)?"