【问题标题】:Angularjs routing manual refreshAngularjs路由手动刷新
【发布时间】:2014-07-30 22:29:41
【问题描述】:

我有一个包含几页的 SPA anularjs 应用程序。

Router Provider配置如下:

$locationProvider.html5Mode(true);

var path = 'web/partials/views/';
$routeProvider
        .when('/', {
            templateUrl: path + 'home.html',
            //controller: 'mainController'
        })
        .when('/benefits', {
            templateUrl: path + 'benefits.html',
            //controller: 'aboutController'
        })
        .when('/gallery', {
            templateUrl: path + 'gallery.html',
            //controller: 'contactController'
        })
        .when('/quote', {
            templateUrl: path + 'quote.html',
            //controller: 'contactController'
        });

这行得通 - 认为 index.html 上的导航链接有效,地址栏获取正确的 url(myapp.com/benefits、myapp.com/quote 等)

不能直接访问 myapp.com/quote 或 myapp.com/benefits 或其他页面。我得到“资源不存在” - 这是有道理的 - 资源真的不存在。

我的问题是 AngularJS 处理这个问题的适当方法是什么?

谢谢!

【问题讨论】:

    标签: angularjs single-page-application angularjs-routing


    【解决方案1】:

    您可以使用错误处理程序(如 $routeChangeError)重定向到默认页面,请查看:

    angular route service

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-30
      • 2016-07-17
      • 2016-02-07
      • 2013-05-24
      • 1970-01-01
      • 2017-11-27
      • 2014-08-28
      相关资源
      最近更新 更多