我有一个平均堆栈的网站。最初,views/index.html
(具有<ui-view></ui-view>
)是所有页面的入口点。它使用angular-ui-router
和html5mode
。因此,浏览器中的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/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
(即,网址为#
),但无论如何这种行为都是奇怪的或不令人满意的。有谁知道如何解决它或有一个解决方法?
https:// stackoverflow的重复项。COM /问题/ 44604703 /加办公室-JS-禁用-html5mode/44858254#44858254。 –