reactjs - React Router <redirect> not working -


i have configured react-router redirect unknown url "/":

<router history={browserhistory}>     <route path="/" component={shell}>         <indexroute component={githubpage}/>         <route path="clock" component={clockpage}/>         <redirect from="*" to="/"/>     </route> </router> 

the server has been correctly configured redirect unknown urls /index.html, looks this:

<html>     <head>         <link href="main.css" rel="stylesheet">     </head>     <body>         <main></main>         <script src="main.js" type="text/javascript"></script>     </body> </html> 

react router 2.8.1 behavior

  • /clock gets routed correctly clockpage
  • /clock/est (which unknown route) not load app. server correctly sends /index.html, css , js files not loaded because browser asking /clock/main.css , /clock/main.js - not exist!
  • to fix issue included <base href="/"> in index.html. browser correctly asks /main.css , /main.js , app loads correctly. redirects "/" because /clock/est unknown route. warning in browser console:

warning: automatically setting basename using <base href> deprecated , removed in next major release. semantics of subtly different basename. please pass basename explicitly in options createhistory

react router 3.0.0 behavior

at point, switched react-router version 3.0.0 (keeping <base href="/">) , warning goes away. unknown route still correctly redirects "/".

so questions are:

  1. does react-router 3.0.0 allow use of <base href>
  2. is solution best way redirect unknown urls "/"?

assume switch on react-router 3.0.0.

if you're generating out css using webpack , you're using htmlwebpackplugin can inject css dependencies in html template so:

<% (var css in htmlwebpackplugin.files.css) { %>   <link href="<%= htmlwebpackplugin.files.css[css] %>" rel="stylesheet"> <% } %> 

then don't have worry using in template.


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -