로그인 화면에서 로그인 성공 시 /dashboard 페이지로 넘어가줘야 하는데 No static resource dashboard 오류가 발생한다.
/dashboard 경로에 해당하는 정적 파일이나 템플릿 파일 또는 컨트롤러가 없을 때 발생
src/main/resources/static/dashboard.html 파일 생성해서 해당 경로에서 접근할 수 있도록 하기index.html에서 모든 경로를 처리할 수 있게 프론트엔드 라우팅을 구성한 후, Spring Boot의 resource handler를 수정해 모든 경로를 index.html로 포워딩하게끔 설정src/main/resources/templates/dashboard.html 파일 생성 (Thymeleaf 등의 템플릿 엔진 사용 시)@Controller
public class DashboardController {
@GetMapping("/dashboard")
public String dashboard(){
return "dashboard"; // dashboard.html 렌더링
}
}/dashboard 경로를 프론트엔드에서 처리하게끔 하고, Spring Boot에서는 해당 경로를 모두 index.html로 포워딩하는 리소스 핸들러를 추가@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry){
registry.addResourceHandler("/**")
.addResourceLocations("classpath:/static/");
}
@Override
public void addViewControllers(ViewControllerRegistry registry){
registry.addViewController("/{spring:\\w+}")
.setViewName("forward:/index.html");
}
}