春季启动与AngularJS html5Mode [英] Spring Boot with AngularJS html5Mode

查看:182
本文介绍了春季启动与AngularJS html5Mode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开始了我与春天启动Web应用程序。它使用一个简单的主类,以启动一个嵌入式Tomcat服务器:

I start my web application with spring boot. It use a simple main class to start an embedded tomcat server:

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }

}

我要配置的服务器,他可以处理angularjs html5mode将与被激活的方式

I want to configure the server in the way that he can handle angularjs html5mode that will be activated with

$locationProvider.html5Mode(true);

从其他用户的相关帖子表明,你需要重定向到根。 HTML5的方式从URL中移除hashbag。如果刷新网页服务器犯规找到页面,因为他不处理的哈希值。请参见:<一href=\"http://stackoverflow.com/questions/15250090/angularjs-why-when-changing-url-address-routeprovider-doesnt-seem-to-work-an\">AngularJS - 为什么要改变URL地址时,$ routeProvider似乎并没有工作,我得到一个404错误

推荐答案

我找到了一个解决方案,我可以住在一起。

I found a solution I can live with it.

@Controller
public class ViewController {

    @RequestMapping("/")
    public String index() {
        return "index";
    }

    @RequestMapping("/app/**")
    public String app() {
        return "index";
    }
}

该angularjs应用程序必须是子域名下的应用程序。如果你不希望出现这种情况,你可以创建这样一个app.subdomain.com的子域MAPPS你的子应用程序。有了这个结构,你有webjars,统计的内容等没有冲突。

The angularjs app has to be under the subdomain app. If you do not want that you could create a subdomain like app.subdomain.com that mapps to your subdomain app. With this construct you have no conflicts with webjars, statis content and so on.

这篇关于春季启动与AngularJS html5Mode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆