window.location.href 和 this.props.history.push 的选择

来源:9-3 添加品类页面的开发

ywang04

2018-05-09

if(categoryName){
            _product.saveCategory({
                parentId        : this.state.parentId,
                categoryName    : categoryName
            }).then((res) => {
                _mm.successTips(res);
                this.props.history.push('/product-category/index');
            }, (errMsg) => {
                _mm.errorTips(errMsg);
            });
        }

this.props.history.push('/product-category/index') 如果换成window.location.href = '/product-category/index' 也是可以的,不知道老师推荐用哪个?

写回答

2回答

Rosen

2018-05-10

能用push的时候就用push,window.location.href会重新加载所有东西,不得已才用

0
0

棒棒锤皮皮虾

2018-05-09

两者都一样 this.props.history.push本质就是window.location.href

0
3
ywang04
回复
棒棒锤皮皮虾
参考老师的回复 应该是这样的。
2018-05-10
共3条回复

React16+React-Router4 打造企业级电商后台管理系统

【毕设面试】让缺乏框架开发经验的你掌握框架开发

976 学习 · 405 问题

查看课程