Monday, June 3, 2024
 Popular · Latest · Hot · Upcoming
10
rated 0 times [  16] [ 6]  / answers: 1 / hits: 26235  / 8 Years ago, thu, june 16, 2016, 12:00:00

I used react-router, even tried <Redirect .. />, I can't redirect to the /, the main problem is the / is out of the other routes, so I need to use <Redirect from=* to= />, it seems to not work.



then I also need to prevent /main redirecting to /, I put the <Redirect .. > after <Route component={MainView} path=main>



another requirement, how make the localhost:3000 to localhost:3000/ to use AppIndex IndexRoute



please check code below:



import MainView from 'components/MainView';
import ThemeIndex from 'components/ThemeIndex';
import AppIndex from 'components/ThemeIndex';
import Shop from 'components/Shop';
import App from 'components/App';

export default (
<Route component={App} path=/>
<IndexRoute component={AppIndex}></IndexRoute>
<Route component={MainView} path=main>
<IndexRoute component={ThemeIndex}></IndexRoute>
</Route>
<Redirect from=* to= />
</Route>
);


have any idea?


More From » reactjs

 Answers
22

Instead of leaving to an empty string, you have to specify the path, which means <Redirect from=* to=/ /> in this case.



To make the localhost:3000 to localhost:3000/, you don't have to do anything, your current code already get the job done.
If you go to any website's root URL, Say http://stackoverflow.com, and try type location.pathname in console, you'll get /



Please ask me if you have any other problem.


[#61749] Tuesday, June 14, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
maureen

Total Points: 151
Total Questions: 110
Total Answers: 110

Location: Mali
Member since Fri, Dec 3, 2021
3 Years ago
maureen questions
Mon, Oct 11, 21, 00:00, 3 Years ago
Wed, Jun 30, 21, 00:00, 3 Years ago
Thu, Apr 15, 21, 00:00, 3 Years ago
Tue, Mar 16, 21, 00:00, 3 Years ago
Mon, Dec 7, 20, 00:00, 4 Years ago
;