-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
[fixed] Link module adds an extra space to className #1295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I'm not sure why you'd want to do this. What is "invariant issue"? |
It means that the component that has been rendered on the server is different from the component rendered on the client side. I am using nginx and stripping part of the url on the server. Which means that the active link rendered on the server side isn't going to be active when rendered on the client because the url route is different.
|
@ryanflorence is there any chance this can go in the next release it would really help me out. Thanks! |
I think with |
@cody it still adds a space to the class |
I would suggest something similar like this: @@ -45,7 +45,6 @@ export var Link = React.createClass({
getDefaultProps() {
return {
- className: '',
activeClassName: 'active',
style: {}
};
@@ -81,8 +80,10 @@ export var Link = React.createClass({
// ignore if rendered outside of the context of a router, simplifies unit testing
if (router && router.isActive(to, query)) {
- if (props.activeClassName)
- props.className += ` ${props.activeClassName}`;
+ if (props.activeClassName) {
+ props.className = props.className ? `${props.className} ` : '';
+ props.className += `${props.activeClassName}`;
+ }
if (props.activeStyle)
Object.assign(props.style, props.activeStyle); That removes the superfluous space from the |
@cody @ryanflorence I changed it to a bug fix. The last commit fixes the extra space that is rendered when @@ -80,9 +80,10 @@ export var Link = React.createClass({
});
// ignore if rendered outside of the context of a router, simplifies unit testing
- if (router && !props.disableActiveClass && router.isActive(to, query)) {
- if (props.activeClassName)
- props.className += ` ${props.activeClassName}`;
+ if (router && router.isActive(to, query)) {
+ if (props.activeClassName) {
+ props.className += props.className !== '' ? ` ${props.activeClassName}` : props.activeClassName;
+ } |
@ryanflorence can you change the tag to bug? |
Thanks for your work on this @sherodtaylor, but this PR is a little messy. In order to merge, will you please:
If that's too much to ask, I'll do it myself. But if you'd like to make it easy on me to push the merge button, I'd really appreciate it :) |
@mjackson no worries I can do that :) |
@mjackson done :) |
[fixed] Link module adds an extra space to className
Thanks @sherodtaylor ! |
@mjackson np :) |
It renders differently on the server because the url on server is stripped by nginx and it is not an active route.