使用ui.router当我刷新或尝试输入直接链接

时间:2016-06-29 04:52:45

标签: angularjs express routing angular-ui-router

奇怪的行为,我不确定是什么导致它。但是当我尝试刷新我的任何页面时,我收到“无法获取/页面”错误。

我实施了这个解决方案:ui-router returns: "Cannot GET /page"

但是现在我的CSS文件中的图像和我用于滑动的脚本,“滑动”不再出现。

这是我的代码。

'use strict';

    angular
      .module('clientApp', [
    'ngAnimate',
    'ngCookies',
    'ngResource',
    'ui.router',
    'ngSanitize',
    'ngTouch'
  ])
  .controller('homeController', function($rootScope){
    $rootScope.page = 'main';
  })
  .config(function ($stateProvider, $urlRouterProvider,    $locationProvider) {

    $urlRouterProvider.otherwise('main');

    $stateProvider
      .state('main', {
        url:'/main',
        templateUrl: 'views/main.html',
        controller: 'MainCtrl'
      })
      .state('bus_internet', {
        url:'/bus_internet',
        templateUrl: 'views/business_internet.html',
        controller: 'busInter'
      })
      .state('bus_voip', {
        url:'/bus_voip',
        templateUrl: 'views/business_voip.html',
        controller: 'busVoip'
      }).
      state('business_active_buildings', {
        url: '/business_active_buildings/:search',
        templateUrl: 'views/business_active_buildings.html',
        controller: 'businessActiveBuildings'
      }).
      state('business_order', {
        url:'/business_order',
        templateUrl:'views/business_order.html',
        controller: 'businessOrder'
      })
      .state('business_voip_features',{
        url:'/business_voip_features',
        templateUrl: 'views/business_voip_features.html',
        controller: 'businessVoipFeatures'
      })
      .state('residential_internet', {
        url:'/residential_internet',
        templateUrl:'views/residential_internet.html',
        controller:'residentialInternet'
      })
      .state('residential_voip', {
        url:'/residential_voip',
        templateUrl:'views/residential_voip.html',
        controller:'residentialVoip'
      })
      .state('residential_active_buildings', {
        url:'/residential_active_buildings',
        templateUrl:'views/residential_active_buildings.html',
        controller:'residentialActiveBuildings'
      })
      .state('thanks_order', {
        url:'/thanks_order',
        templateUrl: 'views/thanks_order.html'
      }) 
      .state('residential_order', {
        url:'/residential_order',
        templateUrl:'views/residential_order.html',
        controller: 'residentialOrder'
      })
      .state('about', {
        url:'/about',
        templateUrl:'views/about.html',
        controller: 'about'
      })
      .state('faq', {
        url:'/faq',
        templateUrl:'views/faq.html',
        controller:'faq'
      })
      .state('marina_internet', {
        url:'/marina_internet',
        templateUrl:'views/marina_internet.html',
        controller: 'marinaInternet'
      })
      .state('marina_order', {
        url:'/marina_order',
        templateUrl:'views/marina_order.html',
        controller: 'marinaOrder'
      })
      .state('jobs', {
        url:'/jobs',
        templateUrl:'views/jobs.html',
        controller: 'jobs'
      })
      .state('thanks_apply', {
        url:'/thanks_apply',
        templateUrl:'views/thanks_apply.html'
      })
      .state('contact_us', {
        url:'/contact_us',
        templateUrl:'views/contact_us.html',
        controller:'contactUs'
      })
      .state('partner_order', {
        url:'/partner_order',
        templateUrl:'views/partner_order.html',
        controller:'partnerOrder'
      });


      $locationProvider.html5Mode(true);


      });

我想知道它是否与我的Express应用程序配置有关:

var express = require('express');
var path = require('path');
var favicon = require('serve-favicon');
var logger = require('morgan');
var cookieParser = require('cookie-parser');
var bodyParser = require('body-parser');

var routes = require('./routes/index');
var users = require('./routes/users');
var sendmail = require('./routes/sendmail');
var test = require('./routes/test');


var app = express();

// uncomment after placing your favicon in /public
//app.use(favicon(path.join(__dirname, 'public', 'favicon.ico')));
app.use(logger('dev'));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(cookieParser());

/**
 * Routes
 */
app.use('/sendmail', sendmail);
app.use('/test', test);


/**
 * Development Settings
 */
if (app.get('env') === 'development') {
    // This will change in production since we'll be using the dist folder
    app.use(express.static(path.join(__dirname, '../client')));
    // This covers serving up the index page
    app.use(express.static(path.join(__dirname, '../client/.tmp')));
    app.use(express.static(path.join(__dirname, '../client/app')));

    // Error Handling
    app.use(function(err, req, res, next) {
        res.status(err.status || 500);
        res.render('error', {
            message: err.message,
            error: err
        });
    });
}

/**
 * Production Settings
 */
if (app.get('env') === 'production') {

    // changes it to use the optimized version for production
    app.use(express.static(path.join(__dirname, '/dist')));

    // production error handler
    // no stacktraces leaked to user
    app.use(function(err, req, res, next) {
        res.status(err.status || 500);
        res.render('error', {
            message: err.message,
            error: {}
        });
    });
}






module.exports = app;

1 个答案:

答案 0 :(得分:0)

您应该将代码更改为此

(function () {
'use strict';
angular
  .module('clientApp', [
'ngAnimate',
'ngCookies',
'ngResource',
'ui.router',
'ngSanitize',
'ngTouch']).controller('homeController', function($rootScope){
$rootScope.page = 'main';}).config(function ($stateProvider, $urlRouterProvider,    $locationProvider) {

$urlRouterProvider.otherwise('main');

$stateProvider
  .state('main', {
    url:'/main',
    templateUrl: 'views/main.html',
    controller: 'MainCtrl'
  })
  .state('bus_internet', {
    url:'/bus_internet',
    templateUrl: 'views/business_internet.html',
    controller: 'busInter'
  })
  .state('bus_voip', {
    url:'/bus_voip',
    templateUrl: 'views/business_voip.html',
    controller: 'busVoip'
  }).
  state('business_active_buildings', {
    url: '/business_active_buildings/:search',
    templateUrl: 'views/business_active_buildings.html',
    controller: 'businessActiveBuildings'
  }).
  state('business_order', {
    url:'/business_order',
    templateUrl:'views/business_order.html',
    controller: 'businessOrder'
  })
  .state('business_voip_features',{
    url:'/business_voip_features',
    templateUrl: 'views/business_voip_features.html',
    controller: 'businessVoipFeatures'
  })
  .state('residential_internet', {
    url:'/residential_internet',
    templateUrl:'views/residential_internet.html',
    controller:'residentialInternet'
  })
  .state('residential_voip', {
    url:'/residential_voip',
    templateUrl:'views/residential_voip.html',
    controller:'residentialVoip'
  })
  .state('residential_active_buildings', {
    url:'/residential_active_buildings',
    templateUrl:'views/residential_active_buildings.html',
    controller:'residentialActiveBuildings'
  })
  .state('thanks_order', {
    url:'/thanks_order',
    templateUrl: 'views/thanks_order.html'
  }) 
  .state('residential_order', {
    url:'/residential_order',
    templateUrl:'views/residential_order.html',
    controller: 'residentialOrder'
  })
  .state('about', {
    url:'/about',
    templateUrl:'views/about.html',
    controller: 'about'
  })
  .state('faq', {
    url:'/faq',
    templateUrl:'views/faq.html',
    controller:'faq'
  })
  .state('marina_internet', {
    url:'/marina_internet',
    templateUrl:'views/marina_internet.html',
    controller: 'marinaInternet'
  })
  .state('marina_order', {
    url:'/marina_order',
    templateUrl:'views/marina_order.html',
    controller: 'marinaOrder'
  })
  .state('jobs', {
    url:'/jobs',
    templateUrl:'views/jobs.html',
    controller: 'jobs'
  })
  .state('thanks_apply', {
    url:'/thanks_apply',
    templateUrl:'views/thanks_apply.html'
  })
  .state('contact_us', {
    url:'/contact_us',
    templateUrl:'views/contact_us.html',
    controller:'contactUs'
  })
  .state('partner_order', {
    url:'/partner_order',
    templateUrl:'views/partner_order.html',
    controller:'partnerOrder'
  });
  $locationProvider.html5Mode(true);
  });})();