【发布时间】:2015-05-25 06:24:05
【问题描述】:
我是 Angular 新手,正在尝试了解如何使用 ui-router。
我有以下设置
angular.module('formApp', ['ngAnimate', 'ui.router', 'ui.bootstrap', 'ui.bootstrap.datetimepicker', 'ngResource'])
// configuring our routes
// =============================================================================
.config(function($stateProvider, $urlRouterProvider) {
$stateProvider
// route to show our basic form (/form)
.state('form', {
url: '/',
templateUrl: 'views/home.html',
controller: 'formController'
})
// nested states
// each of these sections will have their own view
// url will be nested (/form/profile)
.state('form.date', {
url: 'date',
templateUrl: 'views/form-date.html'
})
// url will be /form/interests
.state('form.address', {
url: 'address',
templateUrl: 'views/form-interests.html'
})
// url will be /form/payment
.state('form.payment', {
url: 'payment',
templateUrl: 'views/form-payment.html'
}).state('create', {
url:'create',
templateUrl: 'views/create.html',
controller:'formController'
});
// catch all route
// send users to the form page
$urlRouterProvider.otherwise('/');
})
当我最初加载页面时,这工作正常,但如果我键入其中一个路由,例如localhost:3000/date 我的看法不正确。当我到达 localhost:3000/form/date 时它也不起作用
我收到以下错误:Cannot GET /date 和开发者控制台中的 404 Not Found 错误。
谁能帮帮我?
这是我的 html 页面:
home.html
<div class="page-header text-center">
<!-- the links to our nested states using relative paths -->
<!-- add the active class if the state matches our ui-sref -->
<div id="status-buttons" class="text-center">
<a ui-sref-active="active" ui-sref=".date"><span>1</span> Date</a>
<a ui-sref-active="active" ui-sref=".address"><span>2</span> Address</a>
<a ui-sref-active="active" ui-sref=".payment"><span>3</span> Payment</a>
</div>
</div>
<form name="myform" id="signup-form" stripe:form="saveCustomer" novalidate>
<!-- our nested state views will be injected here -->
<div id="form-views" ui-view></div>
</form>
谁能解释一下这里发生了什么?
【问题讨论】:
-
一件事是
ui-srefs 应该有像ui-sref="form.date"这样的状态的全名。
标签: javascript angularjs node.js angular-ui-router url-routing