react-router icon indicating copy to clipboard operation
react-router copied to clipboard

`transition.redirect` to route by name, like `transitionTo`?

Open romeovs opened this issue 11 years ago • 3 comments

I'm trying to call transition.redirect to redirect to a specific route by name.

This just redirects to the url containing that literal name though, unlike transitionTo which does look up the path in my route definition.

romeovs avatar Feb 27 '15 16:02 romeovs

This already works. Can you show us your route config?

mjackson avatar Mar 02 '15 16:03 mjackson

var routes = (
    <Route name="app" path="/" handler={App} >
        <Route name="home"     handler={Home}     path="/" />
        <Route name="login"    handler={Login}    path="login" />
        <Route name="register" handler={Register} path="register"/>
        <Route name="users" handler={ListUsers} path="users"/>
        <Route name="user"   handler={User} path="users/:id">
            <DefaultRoute name="viewUser" handler={require('./components/profile/view')} />
            <Route name="editProfile" handler={require('./components/profile/edit')} path="edit"/>
        </Route>

        <Route name="publications" handler={require('./components/publications/list')} path="publications" />
        <Route name="upload" handler={require('./components/publications/upload')} path="publications/add" />
        <Route name="publication" handler={require('./components/publications/view')} path="publications/view/:id" />

        <NotFoundRoute handler={PageNotFound} />
    </Route>
);

module.exports = routes;

I'm trying to redirect to users (/users/:id, with id from params) doing:

transition.redirect('users', {params: {id: 1}});

romeovs avatar Mar 02 '15 16:03 romeovs

transition.redirect('users', {params: {id: 1}});

should be transition.redirect('users', {id: 1});.

agundermann avatar Mar 02 '15 19:03 agundermann