jhipster react删除#到URL [英] jhipster react remove # to URL

查看:94
本文介绍了jhipster react删除#到URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是社区的新手.我使用Jhipster(Java + React Redux)Monolitica构建了一个电子商务应用程序.我有以下问题:应用程序配置为在URL中显示井号(#),例如... http://localhost:9000/#/.我在React中删除了此参数,一切正常.但是,当我使用Gradle(./gradew)上传应用程序时,它可以运行, http://localhost:9000/.但是,如果您直接在浏览器中输入 http://localhost:9000/home/,我会收到错误404,网页未找到! ----->我的应用程序来检查问题( http://www.severobalanceboard.eco.br -确定),( http://www.severobalanceboard.eco.br/historia -错误404) _

I'm new to the community. I built an e-commercce application with the Jhipster (Java + React Redux) Monolitica. I have the following problem: The application is configured to display a hashtag (#) in the URL for example ... http://localhost:9000/#/. I removed this parameter in React and everything was right. But when I upload the application with Gradle (./gradew) it works, http://localhost:9000/. But if you type directly into the browser http://localhost:9000/home/ I get ERROR 404, Page not found! -----> my application to check the problem (http://www.severobalanceboard.eco.br - OK), (http://www.severobalanceboard.eco.br/historia - ERROR 404) _

我认为这是Spring的问题.

I think this problme by Spring.

推荐答案

已解决,使用Jhipster和React [Spring + ReactJs]删除了Hash标签#To URL.我使用@GaëlMarziou告诉我的链接.

Resolved, for remove Hash tag # To URL, using Jhipster and React [Spring + ReactJs]. I use the link of @Gaël Marziou told me.

进行修改:

==反应==

1-com/mycompany/myapp/src/main/webapp/app/app.tsx

1 - com/mycompany/myapp/src/main/webapp/app/app.tsx

import { BrowserRouter as Router } from 'react-router-dom'; 
// import { HashRouter as Router } from 'react-router-dom';

2-com/mycompany/myapp/src/main/webapp/index.html

2 - com/mycompany/myapp/src/main/webapp/index.html

<!-- <base href="./"/> -->
<base href="/"/> 

3-com/mycompany/myapp/webpack/webpack.prod.js

3 - com/mycompany/myapp/webpack/webpack.prod.js

},
  devServer: {
    historyApiFallback: true, /*insert this line - only use for develop*/
    stats: options.stats,
    hot: true,
    contentBase: './build/www',
    proxy: [{
      context: [
...

== JAVA ==

==JAVA==

4-com/mycompany/myapp/src/main/java/br/com/MyApp/config/WebConfigurer.java

4 - com/mycompany/myapp/src/main/java/br/com/MyApp/config/WebConfigurer.java

@Bean 
    public Html5RouteFilter html5RouteFilter() { 
        return new Html5RouteFilter(); 
    } 

5-com/mycompany/myapp/src/main/java/br/com/MyApp/web/Html5RouteFilter.java 您需要创建此文件

5 - com/mycompany/myapp/src/main/java/br/com/MyApp/web/Html5RouteFilter.java YOU NEED CREATE THIS FILE

打包com.mycompany.myapp.web;

package com.mycompany.myapp.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.filter.OncePerRequestFilter;

import javax.servlet.FilterChain;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.regex.Pattern;

/**
 * Filter that distinguishes between client routes and server routes  when you don't use '#' in client routes.
 */
public class Html5RouteFilter extends OncePerRequestFilter {

    private Logger log = LoggerFactory.getLogger(getClass());


    // These are the URIs that should be processed server-side
    private static final Pattern PATTERN = Pattern.compile("^/((api|content|i18n|management|swagger-ui|swagger-resources)/|error|h2-console|swagger-resources|favicon\\.ico|v2/api-docs).*");

    @Override
    protected void doFilterInternal(HttpServletRequest request,
                                    HttpServletResponse response,
                                    FilterChain filterChain)
        throws ServletException, IOException {
        if (isServerRoute(request)) {
            filterChain.doFilter(request, response);
        } else {
            RequestDispatcher rd = request.getRequestDispatcher("/");
            rd.forward(request, response);
        }
    }

    protected static boolean isServerRoute(HttpServletRequest request) {
        if (request.getMethod().equals("GET")) {
            String uri = request.getRequestURI();
            if (uri.startsWith("/app")) {
                return true;
            }
            return PATTERN.matcher(uri).matches();
        }
        return true;
    }
}

=== END == 现在要开心

===END== now be happy

这篇关于jhipster react删除#到URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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