2017-12-18 315 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.'; 
}); 
相關問題