且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

NextJS:在多个页面的多个路由中使用相同的组件

更新时间:2023-11-22 09:44:04

可以在 orderSearchBar.js 中区分当前位置通过获取 window.location 对象的路径名.

You can differentiate the current location in your orderSearchBar.js by getting the pathname of window.location object.

onSubmit(e) {
    e.preventDefault();
    const t = {
        nature: this.state.nature,
        type: this.state.type,
        searchBy: this.state.searchBy,
        startDate: this.state.startDate,
        endDate: this.state.endDate,
        keyword: this.state.keyword
    }
    const pathName = window && window.location.pathname;
    const destination = (pathName === '/purchases') ? '/purchaseDetails' : '/orders'
    axios.post(destination, t)..then(res => console.log(res.data));

    this.setState({
        nature: '',
        type: '',
        searchBy: '',
        startDate: '',
        endDate: '',
        keyword: ''         
    });
}