browserHistory 如何在开发环境和生成环境下使用?
根据官方文档 import {browserHistory} from 'dva/router'; // 1. Initialize const app = dva({ history: browserHistory, });
这样是正常的 但是 访问路由下面的其他页面 变成了 not found。 当url 带有# 的字符 就是正常的 。请指教
用browserHistory后, 需要服务器配置泛路由, 把所有路由都指向到index.html文件
请教 @lincenying @sorrycc 所以如果是采用dva-cli创建的脚手架,里面以dora作为开发server的时候,应该如何配置呢? 另外如果正常部署线上环境(用atools-build生成)又应该怎样做呢?
请问有教程或者demo么 求一份 谢谢@lincenying @sorrycc
开发模式下
用 dora-plugin-browser-history,记得指定 index 。
生成环境
需要服务端支持,配 nginx 或者在服务端(比如 node)批量处理路由,例子:https://github.com/sorrycc/dva-boilerplate-isomorphic/blob/master/server/server.js#L22
works like a charm ✌️ thx @sorrycc
补充下 nginx 的简单配置:
server {
listen 8088;
listen [::]:8088;
root /opt/web/static;
location / {
try_files $uri /index.html;
}
}
把 atool-build 生成出来的
index.css
index.html
index.js
放到 nginx root 下就可以了,这里用的 /opt/web/static
location / {
try_files $uri /index.html;
}
这样不刷新页面是没有问题的。 我遇到的问题是dev.site/foo/bar当路由到这个页面的时候,f5刷新, 那么js,css等资源文件的路径也都变化成了
dev.site/foo/bar/common.js
...
dev.site/foo/bar/index.css
不知道我这个情况怎么配置nginx谢谢
@xjdata 资源文件的链接用绝对路径,比如 /common.js。
@sorrycc 谢谢。
roadhog server 开发环境如何使用browser history呢
同样求助,roadhog server 开发环境如何使用browser history呢