【发布时间】:2017-07-01 04:46:51
【问题描述】:
我有一个平均堆栈网站。最初,views/index.html(具有<ui-view></ui-view>)是所有页面的入口点。它使用angular-ui-router 和html5mode。因此,浏览器中的https://localhost:3000/XXXX 将保持不变(而不是添加#)并根据路由器显示相应的内容。
然后,我希望服务器也提供 Office 加载项。我将需要包含office.js 的views/addin.html 和另一个路由器,以便该站点提供一组网址https://localhost:3000/addin/XXXX,我不介意它是否为html5mode(网址可以包含#某处)。
所以这里是routes/index.js的对应:
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/new 和https://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(即url 有#),但无论哪种方式的行为都是奇怪的或不令人满意的。有谁知道如何解决它或有解决方法?
【问题讨论】:
标签: javascript angular-ui-router ms-office office-js html5mode