Material-UI Button Component Doesn't Work Properly After Deploy On Github Pages
<Button href={node.slug}>
<span>Read more</span>
</Button>
So basically this is a button in a Card component, i don't think more code would present more meaning, please ask for more if needed. The node.slug variable is something like "product-name". In local environment works fine, but not after deployment on Github pages.
This is a button on a product-category page(i.e. /tools or /maintenance), clicking the button the first time, takes me to:
xxx.github.io/project-name/product-name/
Issue is that after i go back and then click the button again, /product-category/ gets added to the URL:
xxx.github.io/project-name/product-category/product-name/
This is not the link i want to be at, as there is no page here. The first URL is where i want to be, as that's the URL type where products are at. /product-category/ will not go away unless i click the Home Page button.
Answer
If I infer correctly node.slug
is something like "product-name"
.
That means that it is not an absolute path, and therefore you can interpret it as ./product-name
.
Try with:
<Button href={`/project-name/${node.slug}`}> ... </Button>
Another approach would be to change your base href of your pages. Add a <base>
element in you <head>
:
<head>
...
<base target="_blank" rel="nofollow noreferrer" href="http://xxx.github.io/project-name/">
</head>
Then all your non-absolute href
s will start from that base.
Don’t forget to add a /
at the end of the base
’s href
!
Related Questions
- → Import statement and Babel
- → should I choose reactjs+f7 or f7+vue.js?
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → .tsx webpack compile fails: Unexpected token <
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → React Native with visual studio 2015 IDE
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
- → How do I determine if a new ReactJS session and/or Browser session has started?
- → Alt @decorators in React-Native
- → How to dynamically add class to parent div of focused input field?