(我重新編輯我最初的問題,以更好地解釋上下文。)一臺服務器可以提供2個angularjs模塊/路由嗎?
我有angular-ui-router
和html5mode
內置平均堆棧網站。 routes/index.js
包含以下代碼,它是views/index.html
其中有<ui-view></ui-view>
並且是所有頁面的入口點。因此,瀏覽器中的https://localhost:3000/XXXX
將保持不變(而不是添加#
),並顯示基於路由器的相應內容。現在
router.get('*', function(req, res) {
console.log("router.get *");
res.sendfile('./views/index.html');
});
,因爲this problem,我想有views/addin.html
包含office.js
和另一個路由器,使得該網站提供一組URL https://localhost:3000/addin/XXXX
的,我不介意它是html5mode
與否(一url可以包含#
的地方)。爲此,我在routes/index.js
添加一個塊addin
:
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>addinF</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>
</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', function ($stateProvider) {
$stateProvider
.state('addinNew', {
url: '/addin/new',
template: "new page"
})
.state('addinHome', {
url: '/addin/home',
template: "home page"
})
}]);
</script>
</html>
然而,裝載https://localhost:3000/addin/new
或https://localhost:3000/addin/home
只是表明addin content
並沒有顯示在控制檯new page
或home page
;它也沒有提出任何錯誤。
誰能告訴我什麼是缺少的?一臺服務器可以提供2個angularjs模塊或路由嗎?
謝謝......不過'$ urlRouterProvider.otherwise( 「/插件/新」)'會重定向的所有頁面'的https :// localhost:3000/addin/XXXX' to a ** same ** page'https:// localhost:3000/addin/XXXX#/ addin/new',我希望它們根據路由器的不同而不同。請看我編輯的問題... – SoftTimur
不知道有關路由器..但是,簡單地..我試圖告訴你..是如何觸發你的初始狀態。 'appdate.run(['$ state',function($ state){$ state.go(「addinNew」)}])'..有一個(示例) [http://plnkr.co/edit/kf6OhXfxgbkWws1gQ2NA?p=preview] –