Closed linyongfu2013 closed 5 years ago
我把build后的文件直接放在static下就可以了,没有配置任何东西
@MrHeer 你的 config.js 可以发上来看看吗?你的springboot 需要写一个指定根路径【/】的controller 吗?
是你的跨越文件写错了, 而且你可以发完整。你这是网上的吧。你只是要跨越,其他的不要动springboot的不就可以了嘛???
你用了那些包 继承了那些包什么的,你发出来代码 没发现有价值的错误。
@MrHeer @MinHongwei 浏览器地址栏里请求地址是不是应该按前端的路由写?如 http://localhost:8102/user/login
我访问 http://localhost:8102/
报404
@MinHongwei 我把上面那些跨域的配置项全部删除了,还是不行,另外,我的是restful 的接口,没有mvc 的,这个有影响吗?
@MinHongwei @MrHeer
@EnableWebMvc
@SpringBootApplication
//@EnableAutoConfiguration
public class InnerAdminApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(InnerAdminApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
return builder.sources(this.getClass());
}
}
@Configuration
public class WebMvcConfiguration extends WebMvcConfigurerAdapter {
@Override
public void addInterceptors(InterceptorRegistry registry) {
super.addInterceptors(registry);
registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/api/**")
.excludePathPatterns("/api/v1/global/**");
}
}
配置相关的只有这些代码了,还是不行,访问所有路由都报404
@linyongfu2013 我的config.js只改了路由方式
export default {
history: 'hash', // 默认是 browser
}
@MrHeer 不用配置后端接口代理地址吗?
proxy: {
'/api/': {
target: 'http://localhost:8102/inner-admin',
changeOrigin: true,
// pathRewrite: { '^/server': '' },
},
},
@linyongfu2013 反正我没有配置,是注解了的,我的全是默认的,我没有更改,只更改过路由方式
@MrHeer 前端文件放在你的服务器里面,不会存在跨域问题。前端请求路径直接请求服务器路径,不需要配置proxy
@MrHeer 嗯,是这样,我就是这样,放在我自己服务器的
手残老是@错人 @linyongfu2013
@MrHeer @xiaohuoni 老哥们,还是不行啊,springboot 需要配置视图解释器和静态资源访问那些吗?
@linyongfu2013 我什么都没有配置,直接就可以使用
@MrHeer 你的springboot 什么版本?可以分享下你的配置类代码吗?
@linyongfu2013 你在你的文件夹下,丢一个index.html。能访问就行了。
@xiaohuoni 哪个文件夹?
http://localhost:8102/ 这个地址映射的文件夹
@linyongfu2013 static
@MrHeer @xiaohuoni 不行,404
@MrHeer @xiaohuoni
No mapping found for HTTP request with URI [/index.html] in DispatcherServlet with name 'dispatcherServlet'
@MrHeer @xiaohuoni 需要引入模板引擎包吗?
非pro和umi问题
@linyongfu2013 不需要
@linyongfu2013 我的pom.xml
如下,可以参考一下
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>myproject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.0.RELEASE</version>
</parent>
<!-- Additional lines to be added here... -->
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
@MrHeer @xiaohuoni 现在可以访问登录页面了,可是暂时还不清楚改了哪里的代码成功的。。谢谢两位
but,登录成功后跳转,出现报错,但我前后端分离调试的时候是没有问题的, 这怎么解决呢?
Cannot read property 'currentUser' of undefined
build 好之后文件放到 springboot 应用的 static 目录下无法访问,静态资源跨域等都配置了