簡體   English   中英

無法使用Angular JS了解ui路由器行為

[英]cannot understand ui-router behaviour with Angular JS

我是Angel的新手,正在嘗試找出如何使用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時,它也不起作用

我收到以下錯誤:在開發人員控制台中無法獲取/ 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>

任何人都可以澄清這里發生了什么嗎?

嘗試localhost:3000/#/datelocalhost:3000/#/form/date

除非您指定$locationProvider.html5Mode(true); 你應該用# 角應用。 但是,Html5Mode有一些限制,例如,您將無法使用$urlRouterProvider.otherwise(...); 檢查這篇文章 如果您不熟悉Angular,我不建議您使用Html5Mode

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM