我正在构建一个单页网络应用程序(因为我希望在跨页面/状态移动时具有灵活性和速度),但我正在努力解决路由/网址......
在传统的范例中,我会有如下网址:
example.com/tools/population-tool/#currentYear=1950
example.com/tools/income-tool/#country=usa
example.com/nice-story/
example.com/nice-chapter/nice-story/
现在我想用一个为相应路由加载模板和控制器的路由器(例如使用 Backbone)替换它。
我正在考虑使用一个 pages 对象来存储必要的页面信息:
pages : {
tools : {
template : "#tools",
breadcrumb : ["Home","Tools"]
}
nice-story : {
template : "#nice-story",
breadcrumb : ["Home","Stories","Nice Story"]
}
}
使用路由器,我现在想加载正确的内容和页面状态,给定如下 URL:
example.com/#!/tools/population-tool/?currentYear=1950
如果不使用 Hashbang,或者像这样:
example.com/tools/population-tool/?currentYear=1950
您将如何组织此路由以使 url 方案有意义,同时仍然灵活并允许重定向和新的查询字符串参数?