我在一个ASP.NET MVC web应用上使用Sammy路由,最初基于SPA web应用的标准MS模板,该应用使用Knockout和Sammy来管理页面加载/路由。我是Sammy的新手,所以我不太了解它,但是我的期望是/#搜索路径将被执行,即使它是第一个页面加载,但它看起来好像不是。 “/”路由始终在“冷”页面加载中执行。Sammy路由不能按预期工作
基本上,如果我在调试模式下运行应用程序,所有的作品都很好。 #home和#search路线按预期工作。但是,如果在调试时,我这个URL粘贴到一个新的选项卡或浏览器会话:
http://pr-dev.dav1.net.fmcti.com/#search/101-4155
然后,而非/#搜索路径代码执行时,它出现了“/”路线代码执行。无论网址中是否存在#搜索字词,此路由是否始终在新会话中执行?这里是我的主页视图模型的打字稿代码在SPA路由配置:
// configure SPA routing
Sammy(function() {
this.get("#home",() => {
if (app.view() !== self) {
// load page view model
app.view(self);
}
// clear out any search results
self.hideResults();
self.queryTree.refreshDataSource([]);
self.partSummary(new SR.PR.Query.QueryResult());
self.searchBox.setValue("");
});
this.get("/", function() {
this.app.runRoute("get", "#home");
});
this.get("#search/:pn", function() {
if (app.view() !== self) {
app.view(self);
}
const pn = this.params["pn"];
if (pn) {
SR.PR.Query.doPartSearch(self, pn.toUpperCase());
}
});
});
预先感谢您的帮助!
感谢您的及时建议。事实证明,这不是我的问题,但它确实帮助我更好地理解它。我将分开发布我的最终解决方案。 –