Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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> );