remix-run / react-router

Declarative routing for React
https://reactrouter.com
MIT License
53.13k stars 10.31k forks source link

Couple of <Link> questions #2080

Closed dan-gamble closed 9 years ago

dan-gamble commented 9 years ago

How would i use a <Link> in an component that doesn't seem to be the wrapping <App /> comoponent? I get this error:

A <Link> should not be rendered outside the context of history; some features including real hrefs, active styling, and navigation will not function correctly

An example of when i would use this is like: https://github.com/rackt/react-router/blob/master/docs/Introduction.md#adding-more-ui and i would put a <Link> inside of the <Message> component.

Also are you able to <Link toName='nameOfRoute'> to link to a <Route> regardless of it's path?

knowbody commented 9 years ago

which version of React Router are you using? the 1.0.0-rc1 is not using named routes anymore so you would need to specify the path in your <Link to='/YOUR_PATH'>

dan-gamble commented 9 years ago

I'm using: https://github.com/thereactivestack/meteor-react-router/ which seems to require: 'react-router': '1.0.0-rc1',

Is there a reason named routes were removed? I ask because i use Django mainly at the moment which has a function `{% url 'namespace:name' %} which allows me to change paths without breaking my app. Granted paths are rarely changed it's still a nice little feature.

So is the only way to link to Routes via a path?

knowbody commented 9 years ago

Have a look at #1840 there is a discussion about maybe bringing them back.

And yes only via path.

dan-gamble commented 9 years ago

That answers the name question at least thank you :) I do like the Named Component method of doing that though and i could go down that route!

Just a case of finding out how to use <Link> in individual components that don't seem to have access to history

knowbody commented 9 years ago

the other question - putting <Link> in the Message component works fine for me

dan-gamble commented 9 years ago

I thought that might break it as it looks similar to the code i have at home. When i get home today i'll post my code example and see if that makes more sense, thanks for your help :)

knowbody commented 9 years ago

:+1: let me know, closing for now.

dan-gamble commented 9 years ago

Hey, just uploaded my repo :) The Component i was having trouble with was this one: https://github.com/DanGamble89/meteor-webpack-react-kickstart/blob/master/react/index.jsx#L26

That line throws me the error,

knowbody commented 9 years ago

@DanGamble89 are you still having issue with it? sorry I forgot to get back to you.

dan-gamble commented 9 years ago

@knowbody I haven't tried it again since i've uploaded it but i'm pretty sure that repo has the bug. I'll be trying it again this week so i'll post back in here with what i find again :)