jaredatron / simple-react-router

A Simple Router for React

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to use a subdir?

konsumer opened this issue · comments

On a github-pages default deploy, everything is in a subdir. When I test it locally (on it's own host) it works fine, but when I publish the app, it doesn't route because everything is prefixed with the /projectname

I don't have tests for mounting your app under a prefix but simple-react-router really should support this. I'll have to add this feature at some point. If you want to take a stab at it I'll try my best to merge an pull requests you create.

One thing you could do right now is use a babel constant (maybe called URL_PREFIX) everywhere that in development could be set to / and then in production set to /projectname/ and stick it your route definitions as well as all your links.

class StaticRouter extends SimpleReactRouter {
  routes(map){
    map(`${URL_PREFIX}`,                   HomePage)
    map(`${URL_PREFIX}signup`,             SignupPage)
    map(`${URL_PREFIX}login`,              LoginPage)
    map(`${URL_PREFIX}logout`,             LogoutPage)
    map(`${URL_PREFIX}posts`,              PostIndexPage)
    map(`${URL_PREFIX}posts/new`,          NewPostPage)
    map(`${URL_PREFIX}posts/:postId`,      PostShowPage)
    map(`${URL_PREFIX}posts/:postId/edit`, PostEditPage)
    map(`${URL_PREFIX}:path*`,             NotFound) // catchall route
  }
}

<Link href={`${URL_PREFIX}posts`}>...</Link>

Yeh, I ended up doing that.