javascript - Can't navigate to react-router-dom URL's -
there few topics on this one recommends changing webpack , this one recommends setting catch-all.
i using react-router-dom 3 routes; similar story rest of questions on here, / path works neither /cars or /about does.
import react, {component} 'react'; import {render} 'react-dom'; import {browserrouter, route, switch, link} 'react-router-dom';   const home = () => (   <h1>home</h1> )  const car = () => (   <h1>cars</h1> )  const = () => (   <h1>about</h1> )  render(   <browserrouter>     <switch>       <route exact path="/" component={home}/>       <route exact path="/cars" component={car}/>       <route path="/about" component={about}/>     </switch>   </browserrouter>,   document.getelementbyid('container') );   i have tried adding publicpath , historyapifallback webpack config:
module.exports = {   entry: ['./src/index.jsx'],   output: {     path: path.resolve('public'),     filename: 'bundle.js',     publicpath: '/'   },   module: {     loaders: [       {test: /\.js$/,loader: 'babel-loader',exclude: /node_modules/},       {test: /\.jsx$/,loader: 'babel-loader',exclude: /node_modules/}     ]   },   devserver: {     historyapifallback: true   } }   but navigate http://localhost:8080/cars cannot /cars message on browser , load of errors similar this:
refused load font 'data:font/woff;base64,d09grgabaaaaagz8abeaaaaa09gaaqabaaaaaaaaaaaaaaaaaaaaaaaaaabhrevgaaabgaaaac8aaaa0asqc9udqt1maaagwaaatuaaanlwbeyf1r1nvqgaafwgaaaiwaaaezqfk0pvpuy8yaaaxgaaaafaaaabganccw2ntyxaaabfqaaabkwaaakqk8av7y3z0iaaagwqaaabiaaaauggiqq9mcgdtaaazyaaabzcaaavnb3/bhgdhc3aaab9gaaaacaaaaagaaaaqz2x5zgaah2gaaesvaab8yu28l3fozwfkaabkgaaaadyaaaa2bmibvwhozweaagrqaaaaiaaaacqhmqrzag10eaaazhaaaajdaaaeimbmmbxsb2nhaabmtaaaahoaaaiaflxdr21hehaaagjqaaaaiaaaacacjgzgbmftzqaaapaaaacdaaabkbqel8lwb3n0aabpkaaaasmaaas9pi3qfxbyz...w76a3jvvupjzxkbsrtnqohwtv2mt2uusrulbnirkvaxnbdfttvib8uoau4psruq4q7qq2dhpqaduat0ij5ra0ypuafmacmfy6potegv/9d7uttzx72ttexi4jdcuxh7pb67d7i/s05awjaaiysnie6wowc4miycorsex+zexucvqpinsrmadl8wds2asluogp8hfnsyyfcyjre7w8qducys0axjh0zgk7fx991rgon6l7qma6pq+sza0qw1x9+hgnftrbk+f9rsmdptshvnjl4bdwtp8iaeafj8n7bccioyimjy1/kbsadhawcdmkfgxnynlzfmfgwmlayaie4djzehpys+mzkloisrbxqova2vyzzfk0mwsawelftpmegaqyebk4gnpbgtqcygnm+bgcyhigxm7hsvghscizy4narsze5xwwjgoi3i6obgzhfosm5jakkjbiihhh8orxzdnluwsrzwhm0djd+b93a0ruricfla1vcrtyufwbqjimv' because violates following content security policy directive: "default-src 'self'". note 'font-src' not explicitly set, 'default-src' used fallback.      
typically after trying figure out on own 30 minutes, getting frustrated , posting on so; figured out 2 minutes after...!
the configuration added webpack file pointless; seeing serving files using express
the catch-all method needed, had done wrong. have 2 options. proper "catch all" , send everything html file...
app.get('*', (req, res) => {   res.sendfile(approotpath + '/public/index.html'); });   or, if me, want send specific endpoint, can still manage 'other things' can...
app.get('/react*', (req, res) => {   res.sendfile(approotpath + '/public/index.html'); });   a specific mention, because tripped me up, make sure /react*/ , not /react/*
i update routes following , browse them directly...
render(   <browserrouter>     <switch>       <route exact path="/react" component={home}/>       <route exact path="/react/car" component={car}/>       <route path="/react/about" component={about}/>     </switch>   </browserrouter>,   document.getelementbyid('container') );        
Comments
Post a Comment