Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript React Router Basics Navigating and Nesting Routes Index Routes and Redirects

Joshua Rinard
Joshua Rinard
1,260 Points

<IndexRedirect to="html" /> does not redirect to show html sub page. Is it depreciated? Anyone have a fix?

<Route path="courses" component={Courses}> <IndexRedirect to="html" /> <Route path="html" component={HTML} /> <Route path="css" component={CSS} /> <Route path="javascript" component={JavaScript} /> </Route>

<IndexRedirect to="html" /> does not redirect to show html sub page. Is it depreciated? Anyone have a fix?

1 Answer

mangesh hankare
mangesh hankare
1,020 Points

I'm stumbling to same question. I was able to show html context on /courses link using redirect instead of IndexRoute or IndexRedirect but then my error page module stopped working.

const routes = ( <Router> <App> <Switch>

        <Route exact path="/" component={Home} />
        <Route path="/about" component={About} />
        <Route  path="/teachers" component={Teachers} />
        <Courses>
              <Redirect from="/courses" to="/courses/html" />
             <Route  path="/courses/html" component={HTML} />
             <Route  path="/courses/css" component={CSS} />
             <Route  path="/courses/javascript" component={JavaScript} />

        </Courses>

    </Switch>
  </App>

</Router> );