Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

browserHistory 如何在开发环境和生成环境下使用? #180

Closed
ashersmtll opened this issue Oct 20, 2016 · 11 comments
Closed

browserHistory 如何在开发环境和生成环境下使用? #180

ashersmtll opened this issue Oct 20, 2016 · 11 comments

Comments

@ashersmtll
Copy link

根据官方文档
import {browserHistory} from 'dva/router';
// 1. Initialize
const app = dva({
history: browserHistory,
});

这样是正常的 但是 访问路由下面的其他页面 变成了 not found。
当url 带有# 的字符 就是正常的 。请指教

@lincenying
Copy link

用browserHistory后, 需要服务器配置泛路由, 把所有路由都指向到index.html文件

@librae8226
Copy link

请教 @lincenying @sorrycc
所以如果是采用dva-cli创建的脚手架,里面以dora作为开发server的时候,应该如何配置呢?
另外如果正常部署线上环境(用atools-build生成)又应该怎样做呢?

@ashersmtll
Copy link
Author

请问有教程或者demo么 求一份 谢谢@lincenying @sorrycc

@sorrycc
Copy link
Member

sorrycc commented Oct 21, 2016

开发模式下

dora-plugin-browser-history,记得指定 index

生成环境

需要服务端支持,配 nginx 或者在服务端(比如 node)批量处理路由,例子:https://github.com/sorrycc/dva-boilerplate-isomorphic/blob/master/server/server.js#L22

@sorrycc sorrycc closed this as completed Oct 21, 2016
@sorrycc sorrycc changed the title dva怎么清除url 里面的# 和后面的随机字符 browserHistory 如何在开发环境和生成环境下使用? Oct 21, 2016
@sorrycc sorrycc added the faq label Oct 21, 2016
@librae8226
Copy link

works like a charm ✌️
thx @sorrycc

@librae8226
Copy link

librae8226 commented Oct 22, 2016

补充下 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

@xjdata
Copy link

xjdata commented Oct 24, 2016

        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谢谢

@sorrycc
Copy link
Member

sorrycc commented Oct 25, 2016

@xjdata 资源文件的链接用绝对路径,比如 /common.js

@xjdata
Copy link

xjdata commented Oct 25, 2016

@sorrycc 谢谢。

@chengzhenping
Copy link

roadhog server 开发环境如何使用browser history呢

@lehug
Copy link

lehug commented Jan 2, 2018

同样求助,roadhog server 开发环境如何使用browser history呢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants