相关疑难解决方法(0)

Springboot/Angular2 - 如何处理HTML5网址?

我相信这是一个简单的问题,但我找不到答案或至少在搜索中使用正确的术语.

我正在Angular2和我们Springboot一起建立.默认情况下,Angular将使用localhost:8080\dashboard和等路径localhost:8080\dashboard\detail.

如果可能的话,我想避免使用路径作为哈希.正如Angular 文档所述:

路由器的provideRouter函数将LocationStrategy设置为PathLocationStrategy,使其成为默认策略.如果我们愿意,我们可以在引导过程中使用覆盖切换到HashLocationStrategy.

然后...

几乎所有Angular 2项目都应使用默认的HTML 5样式.它生成的URL更易于用户理解.它保留了以后进行服务器端渲染的选项.

问题在于,当我尝试访问时localhost:8080\dashboard,Spring会寻找一些控制器映射到这条路径,它不会有.

Whitelabel Error Page
There was an unexpected error (type=Not Found, status=404).
No message available
Run Code Online (Sandbox Code Playgroud)

我认为最初是为了让我的所有服务都处于不足localhost:8080\api之下localhost:8080\app.但是,如何告诉Spring忽略对此app路径的请求?

Angular2或Boot有更好的解决方案吗?

spring spring-boot angular

40
推荐指数
4
解决办法
2万
查看次数

使用AngularJS html5Mode进行Spring Boot

我用spring boot启动我的web应用程序.它使用一个简单的主类来启动嵌入式tomcat服务器:

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application {

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

}
Run Code Online (Sandbox Code Playgroud)

我想以他能够处理将被激活的angularjs html5mode的方式配置服务器

$locationProvider.html5Mode(true);
Run Code Online (Sandbox Code Playgroud)

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

html5 spring angularjs spring-boot

17
推荐指数
3
解决办法
2万
查看次数

标签 统计

spring ×2

spring-boot ×2

angular ×1

angularjs ×1

html5 ×1