使用多个路由器的优点?

发布于 2024-11-29 06:12:45 字数 233 浏览 0 评论 0 原文

我开始逐步构建我的 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)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

や莫失莫忘 2024-12-06 06:12:45

最初,我会说这取决于您的应用程序架构/功能以及您要做的网站的规模...

单个路由文件的优点

  • 符合规则:越简单总是越好,所以如果你真的不需要多个路由文件,就不要。
  • 多个文件可能会导致冲突问题,而这些问题很难解决。
  • 根据我的个人经验,在开发了一款自制的网络应用程序后,我只在应用程序的目录中保留了一个文件。

但是多个路由文件呢?

但是,如果您有不同的插件来处理内容类型(wiki、仪表板、图库...),并且它们自动实现路由(不会从一个网站更改为另一个网站),那么您可以找到多个路由文件的合法用法。

在这种情况下,您可以专门为每个插件使用小文件,这些插件将自动合并到应用程序路由文件(注意:正如我之前提到的,通过这样做,您可能会遇到文件之间的路由冲突)
在我的自制应用程序中,我使用此解决方案来处理后端(管理)面板,我通过为后端保留“/admin/”路由来“解决”冲突问题,然后所有插件的路由都以它为前缀。

PHP-Framework Symfony 示例

不要将以下内容视为“您应该这样做”,但您可以在此处查看 Symfony 中的操作方式: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

您愿意翻译网址吗?
如果是的话,请记住我的“越简单越好”的说法。你真的需要它吗?我知道它可能会给你一些搜索引擎优化提升,但我认为这不值得挤压。
在这种情况下,您可以为每个应用程序的每种语言使用 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

  • Compliant to the rule: simpler is -always- better, so if you don't really needs multiple routing file, just don't.
  • Multiple files may lead to collision problems that could be a hell to resolve.
  • My personnal experience, after having myself worked on a homemade web app, I kept only one single file in the app's directory.

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

# 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

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)?"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文