how can i change the hash prefix/format of React-router

1k views Asked by At

i'm using react-router in my app. it changes url like this:

xxx/index.html#/a1
xxx/index.html#/a2

but i want this:

xxx/index.html#!/a1
xxx/index.html#!/a2

because of my old app config.
i dont want to change the interface.

i had try to like this <Route path="!/"> <Route name="a1" path="a1" handler={a1}/> <Route name="a2" path="a2" handler={a2}/> </Route> or this <Route path="!"> <Route name="a1" path="a1" handler={a1}/> <Route name="a2" path="a2" handler={a2}/> </Route> but they all got

xxx/index.html#/!/a1

how can i do this ?

1

There are 1 answers

2
Joao Delgado On

You could implement your own CustomLocation.
I've never done this myself, but you could look at the HashLocation implementation and change what's necessary.

Then you could just pass it to Router.run

Router.run(routes, MyCustomLocation, function (Handler) {
  React.render(<Handler/>, document.body);
});