UI路由器没有路由
UI Router not routing
我在父目录中有一个 index.html 文件,加载的是 http://localhost:3000/#/
而不是 sidebar.html 文件。如果我尝试 http://localhost:300/#/home
它会重定向到 todo
没有抛出任何错误。
app.js
'use strict';
angular
.module('App', [
'ui.router'
//'lbServices'
])
.run([ '$rootScope', '$state', '$stateParams',
function ($rootScope, $state, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
}])
.config(['$stateProvider','$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
title: 'Dashboard',
url: '/',
templateUrl: '../shared/sidebar/sidebar.html',
controller: 'sidebarCtrl'
});
$urlRouterProvider.otherwise('todo');
}]);
server.js
var loopback = require('loopback');
var boot = require('loopback-boot');
var app = module.exports = loopback();
// Set up the /favicon.ico
app.use(loopback.favicon());
// request pre-processing middleware
app.use(loopback.compress());
// -- Add your pre-processing middleware here --
// boot scripts mount components like REST API
boot(app, __dirname);
// -- Mount static files here--
// All static middleware should be registered at the end, as all requests
// passing the static middleware are hitting the file system
// Example:
var path = require('path');
app.use(loopback.static(path.resolve(__dirname, '../client')));
app.use(loopback.static(path.resolve(__dirname, '../node_modules')));
// Requests that get this far won't be handled
// by any middleware. Convert them into a 404 error
// that will be handled later down the chain.
app.use(loopback.urlNotFound());
// The ultimate error handler.
app.use(loopback.errorHandler());
app.start = function() {
// start the web server
return app.listen(function() {
app.emit('started');
console.log('Web server listening at: %s', app.get('url'));
});
};
// start the server if `$ node server.js`
if (require.main === module) {
app.start();
}
不确定这是否相关,但最初我的服务器设置为侦听 0.0.0.0:3000,但如果我将其输入 URL 栏,它会转到 Google 搜索。虽然如果我输入 localhost:3000 它似乎有效。我已经将监听端口更改为 localhost:3000。
以防万一,这个 url http://localhost:3000/#/
,它应该触发状态 home - 正在加载 index.html
- 应该意味着路径
templateUrl: '../shared/sidebar/sidebar.html',
设置不正确。使用(例如 chrome)开发人员工具并检查是否正在加载 sidebar.html
。
这个 url http://localhost:300/#/home
导航到 TODO 状态的事实也是正确的,因为 '/home'
没有映射到 home
状态
.state('home', {
...
url: '/',
});
所以默认触发
$urlRouterProvider.otherwise('todo');
注意:根据问题和描述的问题,我希望 index.html
设置正确。它包含 <div ui-view=""></div>
,将用 sidebar.html
填充。这就是为什么我会怀疑部分视图模板的路径错误...
我在父目录中有一个 index.html 文件,加载的是 http://localhost:3000/#/
而不是 sidebar.html 文件。如果我尝试 http://localhost:300/#/home
它会重定向到 todo
没有抛出任何错误。
app.js
'use strict';
angular
.module('App', [
'ui.router'
//'lbServices'
])
.run([ '$rootScope', '$state', '$stateParams',
function ($rootScope, $state, $stateParams) {
$rootScope.$state = $state;
$rootScope.$stateParams = $stateParams;
}])
.config(['$stateProvider','$urlRouterProvider', function($stateProvider, $urlRouterProvider) {
$stateProvider
.state('home', {
title: 'Dashboard',
url: '/',
templateUrl: '../shared/sidebar/sidebar.html',
controller: 'sidebarCtrl'
});
$urlRouterProvider.otherwise('todo');
}]);
server.js
var loopback = require('loopback');
var boot = require('loopback-boot');
var app = module.exports = loopback();
// Set up the /favicon.ico
app.use(loopback.favicon());
// request pre-processing middleware
app.use(loopback.compress());
// -- Add your pre-processing middleware here --
// boot scripts mount components like REST API
boot(app, __dirname);
// -- Mount static files here--
// All static middleware should be registered at the end, as all requests
// passing the static middleware are hitting the file system
// Example:
var path = require('path');
app.use(loopback.static(path.resolve(__dirname, '../client')));
app.use(loopback.static(path.resolve(__dirname, '../node_modules')));
// Requests that get this far won't be handled
// by any middleware. Convert them into a 404 error
// that will be handled later down the chain.
app.use(loopback.urlNotFound());
// The ultimate error handler.
app.use(loopback.errorHandler());
app.start = function() {
// start the web server
return app.listen(function() {
app.emit('started');
console.log('Web server listening at: %s', app.get('url'));
});
};
// start the server if `$ node server.js`
if (require.main === module) {
app.start();
}
不确定这是否相关,但最初我的服务器设置为侦听 0.0.0.0:3000,但如果我将其输入 URL 栏,它会转到 Google 搜索。虽然如果我输入 localhost:3000 它似乎有效。我已经将监听端口更改为 localhost:3000。
以防万一,这个 url http://localhost:3000/#/
,它应该触发状态 home - 正在加载 index.html
- 应该意味着路径
templateUrl: '../shared/sidebar/sidebar.html',
设置不正确。使用(例如 chrome)开发人员工具并检查是否正在加载 sidebar.html
。
这个 url http://localhost:300/#/home
导航到 TODO 状态的事实也是正确的,因为 '/home'
没有映射到 home
状态
.state('home', {
...
url: '/',
});
所以默认触发
$urlRouterProvider.otherwise('todo');
注意:根据问题和描述的问题,我希望 index.html
设置正确。它包含 <div ui-view=""></div>
,将用 sidebar.html
填充。这就是为什么我会怀疑部分视图模板的路径错误...