找到你要的答案

Q:cannot get state in ui-router

Q:无法在UI路由器中获得状态

I am going to make a project in angular but i have problem with ui-router. If i will go to the other state i have error: Cannot GET /404

There are my codes

routes.coffee

angular.module('havanaApp')
.config ($stateProvider, $urlRouterProvider, $locationProvider) ->

  $locationProvider.html5Mode
    enabled: true
    requireBase: false
  $urlRouterProvider.otherwise '/404'
  $stateProvider

  .state 'home',
    url: '/'
    views:
      main:
        templateUrl: 'views/main.html'
        controller: 'HomeCtrl'

  .state '404',
    url: '/404'
    views:
      main:
        templateUrl: 'views/pages/404.html'
        controller: '404Ctrl'

gulpfile.js

gulp.task('connect', function() {
   return $.connect.server({
       root: '.tmp',
       port: 8080,
       livereload: true
   })
});

What I'm doing wrong?

我打算做一个项目的角度,但我有问题的UI路由器。如果我要去另一个状态我有错误:不能得到/ 404

有我的密码

routes.coffee

angular.module('havanaApp')
.config ($stateProvider, $urlRouterProvider, $locationProvider) ->

  $locationProvider.html5Mode
    enabled: true
    requireBase: false
  $urlRouterProvider.otherwise '/404'
  $stateProvider

  .state 'home',
    url: '/'
    views:
      main:
        templateUrl: 'views/main.html'
        controller: 'HomeCtrl'

  .state '404',
    url: '/404'
    views:
      main:
        templateUrl: 'views/pages/404.html'
        controller: '404Ctrl'

gulpfile.js

gulp.task('connect', function() {
   return $.connect.server({
       root: '.tmp',
       port: 8080,
       livereload: true
   })
});

我做错了什么?

answer1: 回答1:

Okay I fixed my problem.

Problem was in bad configuration my gulpfile.js. This code solved my issue

var ModRewrite = require('connect-modrewrite'),

...

gulp.task('connect', function() {
       return $.connect.server({
           root: '.tmp',
           port: 8080,
           livereload: true,
           middleware: function(connect) {
               return [
                ModRewrite([
                    '!\\.html|\\.js|\\.css|\\.ico|\\.png|\\.gif|\\.jpg|\\.jpeg|\\.swf.*$ /index.html [NC,L]'
                ]),
                   connect.static('./app')
               ];
           }
       })
    });

好吧我解决了我的问题。

Problem was in bad configuration my gulpfile.js. This code solved my issue

var ModRewrite = require('connect-modrewrite'),

...

gulp.task('connect', function() {
       return $.connect.server({
           root: '.tmp',
           port: 8080,
           livereload: true,
           middleware: function(connect) {
               return [
                ModRewrite([
                    '!\\.html|\\.js|\\.css|\\.ico|\\.png|\\.gif|\\.jpg|\\.jpeg|\\.swf.*$ /index.html [NC,L]'
                ]),
                   connect.static('./app')
               ];
           }
       })
    });
angularjs  angular-ui-router