Skip to content

Instantly share code, notes, and snippets.

@TwiN
Created December 17, 2017 21:51
Show Gist options
  • Save TwiN/28f4f5037ecd9102775f5172984500fc to your computer and use it in GitHub Desktop.
Save TwiN/28f4f5037ecd9102775f5172984500fc to your computer and use it in GitHub Desktop.
Link a React app using React-Router and bundled with Webpack to a Spring Boot app
package org.twinnation.site;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class WebConfiguration {
@Bean
public WebMvcConfigurerAdapter forwardToIndex() {
return new WebMvcConfigurerAdapter() {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("forward:/index.html");
registry.addViewController("/{spring:\\w+}").setViewName("forward:/");
registry.addViewController("/**/{spring:\\w+}").setViewName("forward:/");
}
};
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment