-
Notifications
You must be signed in to change notification settings - Fork 26.8k
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
Links not working in only some components #70756
Comments
From what you’re describing, it seems like the issue is related to how your buttons and links are implemented in ProjectCard.tsx and HeroContent.tsx, even though they work in NavBar.tsx. This could be related to the structure of your code or how Next.js handles link tags and interactivity. Here are a few potential solutions:1. Verify MUI Button BehaviorSince you're using Material UI (MUI), buttons with href act as anchor () elements. This means you could run into issues if you're not using the correct component for external links. Make sure you’re using Next.js' Link for internal navigation and for external links. Possible Fix in ProjectCard.tsx:
2. Use Next.js Link for Internal NavigationFor internal navigation, it's better to use Next.js' Link component, which handles client-side routing optimization. You can wrap the MUI button with a Link.
3. Remove z-indexYou’re using the class z-10 on your buttons, but it’s possible that some elements above them are blocking interactions. Check the parent components to ensure no other elements with higher z-indexes or positioning (absolute, fixed) are interfering. Let me know if it's ok or not ;) |
I tried and nothing really changes: Its not a problem with my link component as whether i use the one from next js or material ui it wont work. whereas i can use any of them in the navbar Recording.2024-10-04.012410.mp4My Code: import React from "react"; interface Props { // Utility function to split description into chunks of 50 words const ProjectCard = ({ src, src2, src3, src4 ,src5, title, description, href, github }: Props) => { return ( <Card sx={{ backgroundColor: "#1a1a1a", color: "white", borderRadius: 2 }}> {/* Image Section: Flexbox to align images side by side /} {/ First Image */} <CardMedia component="img" height="200" image={src} alt={title} sx={{ width: "48%", objectFit: "cover", borderRadius: 2 }} />
); export default ProjectCard; |
Link to the code that reproduces this issue
https://github.com/ahmed27037/portoflio-space-theme/blob/master/components/main/sub/ProjectCard.tsx
To Reproduce
Make a button or Link component in ProjectCard.tsx or HeroContent.tsx and check if you can click your link it wont work there (ProjectCard.tsx is a component used in HardProjects.tsx and SoftProjects.tsx which you can see in layout.tsx)
Put that same button or link component in NavBar.tsx and it should work fine
Current vs. Expected behavior
Expected: The link should take you to the href
Current: it does in NavBar.tsx but not in HeroContent or ProjectCard.tsx
Code Problem:
ProjectCard.tsx
{href && (
<Button
className="z-10"
size="small"
href={href} // Link to the website
target="_blank"
rel="noopener noreferrer" // Security best practice
variant="contained"
sx={{ backgroundColor: "#007BFF", ":hover": { backgroundColor: "#0056b3" } }}
>
Website
)}
{github && (
<Button
className="z-10"
size="small"
href={github} // Link to the GitHub repository (corrected this line)
target="_blank"
rel="noopener noreferrer" // Security best practice
variant="contained"
sx={{ backgroundColor: "green", ":hover": { backgroundColor: "#0056b3" } }}
>
Github
Provide environment information
Which area(s) are affected? (Select all that apply)
create-next-app
Which stage(s) are affected? (Select all that apply)
next dev (local)
Additional context
I didn't deploy my project so you would have to test it locally by doing git clone then npm run dev and the website should work.
The text was updated successfully, but these errors were encountered: