带有 AngularJS html5Mode 的 Spring Boot [英] Spring Boot with AngularJS html5Mode

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

问题描述

我使用 spring boot 启动我的 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);
    }

}

我想以他可以处理将用

$locationProvider.html5Mode(true);

其他用户的相关帖子显示需要重定向到root.html5 模式从 url 中删除 hashbag.如果您刷新页面,服务器将找不到该页面,因为他不处理哈希.请参阅:AngularJS - 为什么在更改 url 时地址 $routeProvider 似乎不起作用,我收到 404 错误

Relevant postings from other users shows that you need to redirect to the root. the html5 mode remove the hashbag from the url. If you refresh the page the server doesnt find the page cause he do not handle the hash. see: AngularJS - Why when changing url address $routeProvider doesn't seem to work and I get a 404 error

推荐答案

我找到了一个可以接受的解决方案.

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 的子域来映射到您的子域应用程序.使用此构造,您不会与 webjar、statis 内容等发生冲突.

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 的 Spring Boot的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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