我有一个平均堆栈网站。最初,views/index.html
(have <ui-view></ui-view>
) 是所有页面的入口点。它使用angular-ui-router
和html5mode
。因此,https://localhost:3000/XXXX
在浏览器中将保持不变(而不是添加#
)并根据路由器显示相应的内容。
然后,我希望服务器也提供 Office 加载项。我将需要views/addin.html
该 containsoffice.js
和另一个路由器,以便该站点提供一组 urls https://localhost:3000/addin/XXXX
,我不介意它是否html5mode
存在(一个 url 可以包含#
某处)。
所以这里是对应的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 有#
),但无论哪种方式的行为都是奇怪的或不令人满意的。有谁知道如何修复它或有解决方法?