繁体   English   中英

如何在angular中初始化默认路由?

[英]How to initialize default route in angular?

所以我试图在我的应用程序中使用角度路由。 问题是路由“ /”不会自动初始化。 因此,我首先转到“ /”,页面的主要内容为空(根本不加载模板),单击指向/ settings的链接并加载设置,然后单击指向“ /”的链接,正确初始化模板的时间。 那么,如何在开始时将其初始化?

这是我的路由配置:

 app.config(function($routeProvider, $locationProvider) {
          $routeProvider
           .when('/', {
            templateUrl: '/profile.html',
            controller: 'ProfileController',
          }).when('/profile', {
            templateUrl: '/profile.html',
            controller: 'ProfileController',
          }).when('/settings', {
            templateUrl: '/settings.html',
            controller: 'SettingsController'
          });

          $locationProvider.html5Mode({
            enabled: true,
            requireBase: false
          });
        });

我尝试从控制器调用$ location.url(“ / profile”)确实有帮助,但是必须更改url,而我宁愿保留“ /”

otherwise({ redirectTo: "/" })使用otherwise({ redirectTo: "/" })

更新:这里应该是

 $routeProvider
           .when('/', {
            templateUrl: '/profile.html',
            controller: 'ProfileController',
          }).when('/profile', {
            templateUrl: '/profile.html',
            controller: 'ProfileController',
          }).when('/settings', {
            templateUrl: '/settings.html',
            controller: 'SettingsController'
          }).otherwise({ redirectTo: '/' });

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM