2016-08-02 68 views
0

我正在构建单页应用程序的过程中,我希望使用History.js来管理应用程序状态。根据需要,我可以根据需要进行工作,只需点击相应的链接和视图即可。问题是当我刷新屏幕URL地址改变的地方。我知道这是因为我的服务器捕获/并尝试在服务器上查找目录。在使用#之前,我从未遇到过这个问题!或#分隔客户端参数。单页应用程序的History.js用法

app.html/madeUpPage/

我的服务器正在努力寻找madeUpPage目录时通过链接刷新或进入发生。您如何在具有HistoryJS的客户端单页应用程序中解决这个问题?

的客户端负载的index.html和脚本化包含在它的解析未参数和与网址的这种配置预期执行: app.html#madeUpPage

我与历史试过History.options.html4Mode = truewindow.History = { options: { html4Mode: true} }但是。 js v1.8b2这似乎不适用于我。

'use strict'; 
window.History = {options: {html4Mode: true} }; 
require(['js/client-config.js', 
     'js/lib/history-nativejs.js',  // History.js in raw JavaScript, very nice 3rd party utility... used for routing 
     'js/lib/libweb-ui.js', 
     'js/lib/libweb-ajax.js', // LibWeb ajax 
     'js/lib/libweb-jsml.js', // This is the file needed for JSML to run, parse and render your application (main core file) 
     'js/model.js', 
     'js/portfolio.js', // Main class containing viewstate 
     'js/global.js', // The global view model shared for all views in the SPA 
     'js/index.js', // The initial payload required to load the default application content (index/default.js) 
     'js/router.js', 
     'js/layout.js', 
     ], // This takes the raw JavaScript objects places them how they will appear in the layout (the "master page") 


      function coreScriptsLoadedSuccess() { 

      require(['js/controller.js'], function(){ 

       var appController = new PortfolioClientController(defaultAppState); 

       require(['js/events.js'], function domLoadSuccess(){ 
       }); 

      }); 
}); 

我也试过这个线程:Force html4 fallback in history.js

由于任何人谁可以提供一些帮助。

回答

0

把一个?在通过历史URL在pushState上的JS是什么解决了这个问题!

所以不是..

**Before** 

click (()=> History.pushState({ 
      route: route 
      }, document.title + ' '+ route, 
      route); 
**Now** 

click (()=> History.pushState({ 
      route: route 
      }, document.title + ' '+ route, 
      `?view=${route}`);