【问题标题】:AngularJs ui-router not working in Spring bootAngularJs ui-router 在 Spring Boot 中不起作用
【发布时间】:2017-03-18 14:21:01
【问题描述】:

我正在使用带有 Spring Boot 和 Spring Security 的 UI-router 库。 当我尝试访问我定义的路由时,什么都没有发生,我什至在控制台中都没有收到错误。

这是我的 app.js 文件

var app = angular.module("app", ['ui.router']);

app.config(function($stateProvider, $urlRouterProvider) {
//
// For any unmatched url, redirect to /state1
$urlRouterProvider.otherwise("/");
//
// Now set up the states
$stateProvider
    .state('default', {
        url: "/",
        templateUrl: "partials/firstpage.html"
    })

.state('register', {
    url: "/register",
    templateUrl: "partials/register.html"
})

.state('login', {
    url: "/login",
    templateUrl: "partials/login.html"
})

});

index.html 文件:

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">

<script src="assets/js/jquery-2.1.4.js"></script>

<script src="assets/bootstrap/js/bootstrap.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.8/angular.min.js"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-router/0.3.1/angular-ui-router.js"> </script>

<script src="app.js"> </script>
<script src="controllers/navbar.controller.js"> </script>

</head>

<body>
<div ui-view> </div>

</body>

WebSecurityConfiguration 类:

protected void configure(HttpSecurity httpSecurity) throws Exception {
    httpSecurity
            .csrf()
            .disable()
            .exceptionHandling()
            .authenticationEntryPoint(authenticationEntryPoint)
            .and()
            .sessionManagement()
            .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
            .and()
            .authorizeRequests()
            .antMatchers(
                    HttpMethod.GET,
                    "/",
                    "/*.html",
                    "/favicon.ico",
                    "/**/*.html",
                    "/**/*.css",
                    "/**/*.js",
                    "/**/**/*.css",
                    "/**/**/*.js",
                    "/**/**/*.html",
                    "/**/**/**/*.css",
                    "/**/**/**/*.js",
                    "/**/**/**/*.html",
                    "/**/**/**/**/*.css",
                    "/**/**/**/**/*.js"          
            ).permitAll()
            .antMatchers("/auth/**", "/").permitAll()
            .anyRequest().authenticated();

    // Custom JWT based authentication
    httpSecurity
            .addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class);
}

这是我的项目结构: project structure

我应该在我的代码中添加什么来配置用于 Spring 启动的 ui-router 库吗?

【问题讨论】:

标签: angularjs spring spring-mvc spring-boot angular-ui-router


【解决方案1】:

您的 HTML 代码没有 ng-app 指令。所以基本上你的角度应用程序没有被初始化

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-05
    • 1970-01-01
    • 2017-11-20
    • 2015-08-13
    • 2015-02-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多