아우 vue router를 스프링에서 설정해줘야 새로고침이 된다는 사실을 알았네요.

package kr.co.kshproject.webDemo;

import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.Resource;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.resource.PathResourceResolver;

import java.io.IOException;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry
                .addResourceHandler("/**")
                .addResourceLocations("classpath:/static/")
                .resourceChain(true)
                .addResolver(new PathResourceResolver() {
                    @Override
                    protected Resource getResource(String resourcePath, Resource location) throws IOException {
                        Resource requestedResource = location.createRelative(resourcePath);
                        return requestedResource.exists() && requestedResource.isReadable() ? requestedResource : new ClassPathResource("/static/index.html");
                    }
                });
    }

    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("forward:/index.html");
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    }

}

위의 webconfig 클래스를 만들어서 spring에 등록해주고   

.addResourceHandler("/**") 모든 경로 
 .addResourceLocations("classpath:/static/") build 된 vue index.html에 들어가는곳 이네요 .

일단 해결해서 기쁩니다. ㅎ 

 

' > Spring vue 웹 개발' 카테고리의 다른 글

spring vue 연동 회원가입01  (0) 2023.04.19
spring vue 연동 product 01  (0) 2023.04.18
spring vue 연동 slider button image  (1) 2023.04.17
spring vue 로그인 페이지 이동  (0) 2023.04.16
Spring + Vue 연동  (0) 2022.11.20

+ Recent posts