2017-12-18 317 views
0

这看起来可能很奇怪,但我基本上想创建一个HTML文件,该文件与angular/spring启动应用程序无关。Spring Boot/Angular应用程序。路由一个完全自包含的HTML文件

目前:

  • 的 'localhost:8080 /' ---(重定向到角应用 '/#/登录!')

我想要什么:

  • 'localhost:8080/angular'---(在'/#!/ login'重定向到角度应用程序)

  • 'lo calhost:8080 /“---(显示我正常的自包含HTML文件eg'test.html”)

我很新的角度和Spring所以即使只是指导我在正确的方向将是一个巨大的帮助。

谢谢。

+1

https://github.com/angular-ui/ui-router – pegla

回答

1

您应该使用ngRoute。通过“ngRoute”的礼貌,您可以通过特定的URL将用户重定向到特定的视图。请对此进行一些研究。假设你解决了你的观点和重定向问题。你将如何从服务器端获取数据?这时我建议你看看服务和工厂对象。 希望它有帮助。

示例代码:

// create the module and name it exApp 
// also include ngRoute for all our routing needs 

var exApp= angular.module('exApp', ['ngRoute']); 

// configure our routes 
exApp.config(function($routeProvider) { 
    $routeProvider 

     // route for the home page 
     .when('/', { 
      templateUrl : 'pages/home.html', 
      controller : 'mainController' 
     }) 

     // route for the about page 
     .when('/about', { 
      templateUrl : 'pages/about.html', 
      controller : 'aboutController' 
     }) 

     // route for the contact page 
     .when('/contact', { 
      templateUrl : 'pages/contact.html', 
      controller : 'contactController' 
     }); 
}); 

// create the controller and inject Angular's $scope 
exApp.controller('mainController', function($scope) { 
    // create a message to display in our view 
    $scope.message = 'Everyone come and see how good I look!'; 
}); 

exApp.controller('aboutController', function($scope) { 
    $scope.message = 'Look! I am an about page.'; 
}); 

exApp.controller('contactController', function($scope) { 
    $scope.message = 'Contact us! JK. This is just a demo.'; 
}); 
相关问题