我正在尝试在AngularJS 1.5.8中路由一个非常简单的示例组件。花了大约两天时间尝试不同的事情,但这是一个非常简单的例子。
我尝试过使用 ui-view name =“main”。还尝试将URL从“/”更改为“/ path”之类的其他内容,但浏览器返回“无法GET /路径”。所以它告诉我路由根本不起作用。还尝试不使用组件路径并更改为模板。仍然无效(浏览器中没有控制台错误的白页)。
使用angular-ui-router v1.0.0-beta
app.module.js
(function(){
'use strict';
angular.module('mainApp', ['ui.router'])
.component('mainComponent', {
controller: function(){
this.message = "message from the controller";
},
template: 'sample template from app component'
})
.config(function($stateProvider){
var mainState = {
name: 'main',
url: '/',
component: 'mainComponent'
};
$stateProvider.state(mainState);
});
})();
的index.html
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<title>SB Admin 2 - Bootstrap Admin Theme</title>
<!-- Bootstrap Core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- MetisMenu CSS -->
<link href="vendor/metisMenu/metisMenu.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="dist/css/sb-admin-2.css" rel="stylesheet">
<!-- Morris Charts CSS -->
<link href="vendor/morrisjs/morris.css" rel="stylesheet">
<!-- Custom Fonts -->
<link href="vendor/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es6-shim/0.33.3/es6-shim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.20/system-polyfills.js"></script>
<script src="https://npmcdn.com/angular2/es6/dev/src/testing/shims_for_IE.js"></script>
<![endif]-->
<!-- jQuery -->
<script src="vendor/jquery/jquery.min.js"></script>
<!-- AngularJS -->
<script src="bower_components/angular/angular.min.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<!-- Metis Menu Plugin JavaScript -->
<script src="vendor/metisMenu/metisMenu.min.js"></script>
<!-- Custom Theme JavaScript -->
<script src="dist/js/sb-admin-2.js"></script>
<!-- Component Router -->
<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<!-- SPA Resources -->
<script src="app/app.module.js"></script>
</head>
<body ng-app="mainApp">
<ui-view></ui-view>
</body>
</html>