我有一个mean-stack网站。最初,
然后,我想让服务器也提供Office插件。我需要包含
所以这里是
当注释掉
如果取消
我的目标是让指向
views/index.html
(具有<ui-view></ui-view>
)是所有页面的入口点。它使用了angular-ui-router
和html5mode
。因此,在浏览器中,https://localhost:3000/XXXX
将保持不变(而不是添加#
),并显示基于路由器的相应内容。然后,我想让服务器也提供Office插件。我需要包含
office.js
和另一个路由器的views/addin.html
,以便网站提供一组URL:https://localhost:3000/addin/XXXX
,如果其中一个url包含#
,那么我不介意它是否为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中是否有#
),都会出现奇怪或不令人满意的行为。有没有人知道如何解决或有解决方法?