2017-07-01 46 views
1

我有一个平均堆栈的网站。最初,views/index.html(具有<ui-view></ui-view>)是所有页面的入口点。它使用angular-ui-routerhtml5mode。因此,浏览器中的https://localhost:3000/XXXX将保持不变(而不是添加#),并显示基于路由器的相应内容。添加office.js在网址中添加#,然后将其删除

然后,我希望服务器也服务于Office加载项。我将需要views/addin.html,其中包含office.js和另一个路由器,以便该网站提供一组网址https://localhost:3000/addin/XXXX,我不介意它是否为html5mode或不是(某个url可能包含#某处)。

所以这里的routes/index.js的correpsonding:

router.get('/addin/*', function (req, res) { 
    console.log("router.get /addin/*"); 
    res.sendfile('./views/addin.html') 
}); 

router.get('*', function(req, res) { 
    console.log("router.get *"); 
    res.sendfile('./views/index.html'); 
}); 

这里是views/addin.html

<html> 
<head> 
    <title>F-addin</title> 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js"></script> 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.3.2/angular-ui-router.js"></script> 
    <!--<script src="https://appsforoffice.microsoft.com/lib/1/hosted/office.js"></script>--> 
    <base href="/" /> 
</head> 
<body ng-app="addinF"> 
    addin content 
    <ui-view ng-cloak></ui-view> 
</body> 
<script> 
    var addinApp = angular.module('addinF', ['ui.router']) 
    addinApp.config(['$stateProvider', '$locationProvider', function ($stateProvider, $locationProvider) { 
     $stateProvider 
      .state('addinNew', { 
       url: '/addin/new', 
       template: "new page" 
      }) 
      .state('addinHome', { 
       url: '/addin/home', 
       template: "home page" 
      }) 
     $locationProvider.html5Mode(true); 
    }]); 
</script> 
</html> 

office.js在浏览器的工作评价如上,https://localhost:3000/addin/newhttps://localhost:3000/addin/home好。但是,当office.js未注释时,会出现一个奇怪的行为:在浏览器中输入https://localhost:3000/addin/new将更改为https://localhost:3000/#/addin/new,然后更改回https://localhost:3000/addin/new。我们会看到addin content new page出现一次并消失。

随着office.js注释掉,如果我们加载一个清单文件与<SourceLocation DefaultValue="https://localhost:3000/addin/new"/>,我们也会看到在任务窗格中addin content new page出现一次,消失,然后Add-in Error Something went wrong and we couldn't start this add-in. Please try again later or contact your system administrator.

没有html5mode这里,.../addin/new.../addin/home在浏览器将只显示addin content;该加载项可以加载,也只有addin content

我的目标是让一个加载项指向.../addin/new.../addin/home工作。必须在某处加载office.js。我不介意它是否为html5mode(即,网址为#),但无论如何这种行为都是奇怪的或不令人满意的。有谁知道如何解决它或有一个解决方法?

+0

https:// stackoverflow的重复项。COM /问题/ 44604703 /加办公室-JS-禁用-html5mode/44858254#44858254。 –

回答

0

纵观office.js文件的调试版本:

https://appsforoffice.microsoft.com/lib/1/hosted/office.debug.js

你会看到窗口的历史replaceState和pushState的功能被设置为空:

window.history.replaceState = null; 
window.history.pushState = null; 

哪禁用操纵浏览器历史记录的能力,并且似乎Angular认为历史API不可用,所以Angular会回退到hashtag导航。

office.js缩小的版本,你可以通过查找发现这两条线:

window.history.replaceState=e;window.history.pushState=e; 

你可以删除的代码来重新启用html5mode这两条线,但我不知道,如果办公室。 js插件将继续正常工作。

+0

谢谢......我将'office.js'复制到本地,使得'https:// localhost:3000/static/office.js'显示出好的文件。但加载'addin.html'与新的引用给了我一个控制台'未捕获的SyntaxError:意外的令牌<:3000 /静态/ o15apptofilemappingtable.js:1'错误。我总是得到这个错误,无论我删除这两个'window.history'行... – SoftTimur

+0

看到https://stackoverflow.com/questions/44861833/cannot-load-local-office-js – SoftTimur

相关问题