关于导航架构的想法?

发布于 2024-09-18 07:26:43 字数 641 浏览 4 评论 0原文

我正在写一个应用程序。我希望它的各个部分都可以通过单个字符串(例如 URL)访问。我看到了很多不同的方法来实现这一点,并且想知道是否还有其他人正在考虑它。

例如,假设一个 Web 应用程序支持多个不同的留言板。访问板 A 中第三条评论的 URL 可能是 http://msg.com/A/3,我们可能会在 msg.com/A/3/reply 上回复该消息。 URL 不应该有任何状态要求 - 我可以直接访问 msg.com/B/25/reply 来响应 B 板的第 25 条消息。

您将如何构建代码来处理此类导航?假设您知道如何解析 URL。

潜在问题:

  • 有些界面组件不关心它们在哪里,但有些需要知道。注销按钮可以直接转到 msg.com/logoff,而无需关心单击的位置。另一方面,回复按钮(或任何配置回复按钮的内容)需要知道我们现在正在阅读哪个版块和消息,以便它可以链接到正确的地址。

  • 理想情况下,代码将保持分离。这意味着如果我们可以帮助的话,没有所有代码都可以访问和修改的全局字符串。我们可以使用事件总线或注入作为更好的替代方案。

我不知道这是否算作一个问题……我只是在寻找想法,真的!

I'm writing an application. I want various parts of it to be accessible via a single string (e.g. a URL). I see lots of different ways to implement this and wonder if anyone else is thinking about it.

For example, let's assume a web app that supports several different message boards. A URL to access the third comment in board A might be http://msg.com/A/3, and we might respond to that message at msg.com/A/3/reply. There should be no state required of a URL - I can go directly to msg.com/B/25/reply to respond to the 25th message of board B.

How would you structure your code to handle this sort of navigation? Let's assume you know how to parse the URL.

Potential problems:

  • Some interface components don't care where they are, but some need to know. The logoff button can just go to msg.com/logoff without caring where it was clicked. On the other hand, the reply button (or whatever configures the reply button) needs to know which board and message we are reading right now so it can link to the right address.

  • Ideally, the code will stay separated. This means no global string that all code can access and modify if we can help it. We could use an event bus or injection as preferable alternatives.

I don't know if this even counts as a question around here... I'm just looking for thoughts, really!

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

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

发布评论

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

评论(1

涫野音 2024-09-25 07:26:43

这些都是合理的担忧,我花了相当多的时间来让这些问题“恰到好处”地适合我们的产品。您还会遇到许多其他潜在问题,并且不同的技术堆栈在支持这些问题方面具有不同的优势。您的策略在很大程度上取决于您想要对网站做什么。

当你开始研究这个问题并提出更明确的问题时,我认为你应该继续将它们发布在这里。 StackOverflow 更专注于回答定向编程问题,而不是提供思想论坛。

These are valid concerns, and I've spent quite a bit of time getting these issues "just right" for our product. There are a lot of other potential problems that you'll run into, and different technology stacks have different strengths when it comes to supporting those issues. Your strategy will depend heavily on exactly what you want to do with your site.

As you begin working on this, and come up with more defined questions, I think you should continue to post them here. StackOverflow is more focused on answering directed programming questions than it is on providing a forum for thoughts.

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