版本JavaScript的一个单页web应用程序? (查询字符串) [英] Versioning a JavaScript single page web app? (querystring)

查看:139
本文介绍了版本JavaScript的一个单页web应用程序? (查询字符串)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个单页应用程序的一些静态路由,例如:

I have a Single Page App with some static routes such as:

example.org/#!/tools/
example.org/#!/stories/story-1/

这些是不需要任何版本的路线的实例。无论是页的存在,它已被重定向或它是不存在的。

These are examples of routes that don't need any versioning. Either the "page" exists, it has been redirected or it is non-existent.

但后来我还有其他的资源,我想的版本(因为他们可以有内部状态 - 与表示> 10参数查询字符串):

But then I have other resources I'd like to version (because they can have internal states - denoted with a querystring of > 10 parameters):

example.org /#/工具/人口工具/ + = B和!?C = D [...]

example.org/#!/tools/population-tool/ + ?a=b&c=d[...]

由于查询字符串PARAMATERS可能会随时间(作为刀具可能会允许更多的选择)的变化,我想一个版本参数添加到这些页面

Because the querystring paramaters might change over time (as the tool might allow more options), I'd like to add a version parameter to these "pages":

example.org /#/工具/人口工具/ + V = 1.1 &放大器;!?A = B和C = D [...]

example.org/#!/tools/population-tool/ + ?v=1.1&a=b&c=d[...]

这样当用户导航到该URL不带任何参数,默认状态和版本自动添加

So that when a user navigates to the URL without any parameters, the default state and version is automatically added:

example.org/#!/tools/population-tool/ =>
example.org/#!/tools/population-tool/ + version + default state

在情况下,用户决定分享/书签这个URL,版本paramater总会让我从一个版本的PARAMATERS重新映射到另一个。

In case the user decides to share/bookmark this URL, the version paramater will always allow me to remap the paramaters from one version to another.


  1. 您能否提供一个更好的办法?

  2. 或许版本应的URL,所有路线的一部分吗?

  1. Can you suggest a better approach?
  2. Perhaps the version should be a part of the url for all routes?

example.org /#!/ V1 /工具/人口工具/

example.org/#!/v1/tools/population-tool/

或许版本的查询字符串是错误的做法
共?也许我应该有瞎猜的方法
基于参数正确的API中给出?

  • Or perhaps versioning the querystring is the wrong approach altogether? Perhaps I should have a method that guesstimates the right "API" based on the parameters given?

    感谢。

    推荐答案

    从猜测参数正确的API可能是乏味,并会导致不必要在你的路由子系统的复杂性。这是更清洁器具有在URL明确指定的版本的信息。

    Guessing the right API from parameters can be tedious and will lead to unnecessary complexities in your routing sub-system. It is much more cleaner to having the version information clearly specified in the URL.

    现在的做法是否应遵循的是1或2得多的喜好问题。在我看来,这取决于你的应用程序版本如何感知是最终用户。如果您的最终用户不会感觉到在前端(即的变化。如果你是以下MVC架构,虽然视图层保持不变,则接近1推荐更为哪里,就好像它是变化的仅仅是模型层对于用户重要的是要知道哪个版本,他正在使用或如果用户界面可见的最终用户是不同的不同版本则接近2是一个更好的选择,因为它把版本信息在URL中的显着位置。

    Now whether the approach to be followed is 1 or 2 is much of a matter of taste. In my opinion it depends on how perceivable your application version is to the end user. If your end user does not perceive an change in the front-end (ie. if you are following an MVC architecture and the change is only the Model layer while the view layer remains unchanged then approach 1 is more recommended. Where as if it is important for the user to be aware of which version he is using or if the user-interface visible to end user is different across versions then approach 2 is a better option because it puts the version information in a prominent position in the url.

    看着就可以问一个问题,如果应用程序的状态是版本之间的不同的另一种方式。网址(SAN的查询参数)再presents应用程序的状态,并在情况下,答案是真的,那么第二个方法应该得到遵守。但是,如果版本信息被抽象从主应用程序code,距离仅与某些抽象的分节如。只有少数的模型类则接近1应该得到遵守。

    Another way of looking at it can be asking the question if application state is different between versions. A url (sans the query parameters) represents the application state and in case the answer is true then 2nd approach should be followed. However if the version information is abstracted away from the main application code and is relevant only to certain abstracted sub-sections eg. only a few model classes then approach 1 should be followed.

    这篇关于版本JavaScript的一个单页web应用程序? (查询字符串)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆