Micronaut + Angular:刷新页面 [英] Micronaut + Angular : Refresh page

查看:82
本文介绍了Micronaut + Angular:刷新页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Micronaut和Angular 4构建应用程序.

I'm building an application with Micronaut and Angular 4.

我已将Micronaut配置为提供静态资源

I've configured the Micronaut to Serving Static Resources

micronaut:
    router:
        static:
            resources:
                enabled: true
                mapping: /**
                paths: classpath:public

一切正常( DefaultURL路由: http://localhost:8080/dashboard ).Angular应用程序已加载,用户与该应用程序进行交互并正确地浏览了路线.

Everything works well (DefaultURL route:http://localhost:8080/dashboard). The Angular app is loaded and the user interacts with the app and navigate through the routes correctly.

在控制器中,我将服务器配置为重定向到index.html.如果服务器中不存在该路径.

In the controller I configured the server to redirect to index.html.If the path does not exist in the server.

@Get("/{[path:[^\\.]*}")
    @Secured(SecurityRule.IS_ANONYMOUS)
    @Produces(MediaType.TEXT_HTML)
    public HttpResponse<?> refresh() {
        return HttpResponse.redirect(URI.create("/index.html"));
    }

但是当用户刷新页面时(例如,按F5键).

But when the user refreshes the page (e.g. pressing F5).

如果当前网址为" http://localhost:8080/userdetails/status "刷新后,Angular应用将转到默认路由" http://localhost:8080/仪表板" ,而不是用户在" http://localhost:8080/userdetails/status "

If the current Url is "http://localhost:8080/userdetails/status" after refresh the Angular app goes to the default route "http://localhost:8080/dashboard", instead of the route which the user was in "http://localhost:8080/userdetails/status"

请帮助我谢谢

推荐答案

查找下面已实现的工作代码.

Find the Working Code below which I have been implemented.

@Controller("/")
public class IndexController {
    @Inject
    ResourceResolver res;


    @Get("/{[path:[^\\.]*}")
    @Secured(SecurityRule.IS_ANONYMOUS)
    @Produces(MediaType.TEXT_HTML)
    public HttpResponse<?> refresh(HttpRequest<?> request) {
        StreamedFile indexFile = new StreamedFile(res.getResource("classpath:public/index.html").get());
        return HttpResponse.ok(indexFile);
    }
}

这篇关于Micronaut + Angular:刷新页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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