Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error "Cannot GET" url in browser after refresh a Redux component

I'm rendering the following component properly on the URL localhost:8080/productDesc/433899641 on first load navigating from another component. However when refreshing the page, browser does not load React and returns in the display the error message "Cannot GET /productDesc/433899641" and nothing in the console to debug

import React from 'react'

const ProductDesc = (props)=>{

    function test(element,index,array){
      var convertId = Number(productId)
      if(element.id === convertId){
        return true;
      }
    }
    const products  = props.products;
    const productId = props.params.itemId;

    const i = products.findIndex(test);

    const product = products[i];
    console.log(product);

    return (
     <ProductComponent />
    )

}

ProductDesc.propTypes = {
  products: React.PropTypes.array
};

export default ProductDesc;

My routing is as below

  <Provider store={store}>
    <Router history={ history }>
      <Route path="/" component={ App }>
          <IndexRoute component={ ProductsGrid } />
          <Route
            path="/productDesc/:itemId"
            component={ ProductDesc }
          />
      </Route>
    </Router>
  </Provider>

How am i supposed to keep the current state and reload it? I'm using Redux

like image 460
Nicc Avatar asked Mar 26 '26 11:03

Nicc


1 Answers

In order to survive the server reload, your server needs to support it too by responding with index.html no matter what path is requested. Otherwise, use hashHistory instead of browserHistory.

like image 154
goldbullet Avatar answered Mar 29 '26 01:03

goldbullet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!