React-Router 1.0 - 100% Client Side Routing - Page Refresh causes 404 error -


i creating website client use strictly client side react-routing script.

here sample of router ....

import react 'react'; import { route } 'react-router'; import { generateroute } '../utils/localized-routes';  export default (   <route component={ require('../components/app') }>     { generateroute({       paths: ['/', 'audience'],       component: require('../components/audience')     }) }     { generateroute({       paths: ['speaker'],       component: require('../components/speaker')     }) }     { generateroute({       paths: ['board'],       component: require('../components/board')     }) },     { generateroute({       paths: ['questions'],       component: require('../components/parts/askquestion')     }) }     <route path="*" component={ require('../pages/notfound') } />   </route> ); 

with being code generateroute:

export function generateroute({ paths, component }) {   return paths.map(function(path) {     const props = { key: path, path, component };     // static `onenter` defined on     // component, should pass route props     if (component.onenter) props.onenter = component.onenter;     return <route {...props} />;   }); } 

problem:

while understand links bypass server navigation , utilize transition (client side), on page refresh, "page cannot found".

  1. if manually put hash tag before browser's url input (myexample.com/#speaker), page appears, of course cannot expect user that.

  2. if must use hash tags allow client side routing, put them? put them in and/or router, neither work.

  3. alternatively, can achieve total client side routing w/o ugly hash tags? if, so, how do it?

i'd prefer solution based on #3, if else fails i'll take solution based on #2.

any ideas?

thanks in advance.

i find solution using step #2 above , stuck hashtags.

import react 'react'; import reactdom 'react-dom'; import router 'react-router'; import createhistory 'history/lib/createhashhistory'; <-- using //  import createbrowserhistory 'history/lib/createbrowserhistory';   const routerprops = {   routes: require('./router/routes'),   history: createhistory({            <--- added remove ugly querystring     querykey: false   }),   createelement: (component, props) => {     return react.createelement(component, { ...props });   } };  reactdom.render(     react.createelement(router, { ...routerprops }),     document.getelementbyid('root')   ); 

would still know how can remove hashtags client-side routing.


Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -