reactjs - react-router not changing pages -
no matter route access, react-router (v4) returning home page, when route parsing urls , render switch statement, works fine.
import { browserrouter router, route, switch } 'react-router-dom' const home = () => <div>home page</div> const = () => <div>about page</div> render(( <router> <switch> <route path="/" component={home} /> <route path="/about" component={about} /> </switch> </router> ), document.getelementbyid('root'))
i'm using apache server , laravel/php backend, urls localhost/calendar/public
, localhost/calendar/public/about
, might problem. however, whenever use route (e.g. localhost/calendar/public/foo
) server returns page not exist.
edit
here's way got working, it's more of hack solution , i'm still not sure why original problem arose.
import { browserrouter router, route, switch } 'react-router-dom' const url = new url(window.location.href) const isdev = (url.host == "localhost") const browserapp = ( <router> <switch> <route exact path={`${isdev ? "/calendar/public/" : "/"}`} component={home}/> <route path={`${isdev ? "/calendar/public/about" : "/about"}`} component={about}/> </switch> </router> )
you need pass history
object <router ... />
component or use 1 of high-level routers e.g. <browserrouter />
. see docs:
Comments
Post a Comment