link to anchor from URL using react - node.js

I have a FAQ page i have created with many questions and answers in the form of
<div>
<h4 id="anchor-name">question</h4>
<p>answer</p>
</div>
This works as expected if i have a button or clickable link in the form of
Click here to go to anchor
which takes me directly to my question with that id (expected behaviour)
The problem is when i try to access this from a URL from another tab by doing something like
https://my-app-url/#/FAQ/#anchor-name
it redirects me to my FAQ page but not to my question. Instead, it just loads the FAQ and stays on the top.
Some context:
frontend is in react
the first # in the url https://my-app-url/#/FAQ/#anchor-name is mandatory. Apparently if i just go with https://my-app-url/FAQ/#anchor-name it never loads the page
I have tried enclosing the <div> tags and the <h4> tags by an <a> tag but it didn't work. In those cases what i did was
<div>
<a href="#anchor-name">
<h4 id="anchor-name">question</h4>
<p>answer</p>
</a>
</div>
What i wish to know and cannot seem to find it by doing research a lot is:
Is it possible to access this anchor via URL from an external link by using react-router library?
Could it be that by using react the html way to anchor is not working as expected?
Is my first # in the URL interfering with the anchor linking feature?

You don't need that last / right before the #anchor-tag.
so the URL would be:
https://my-app-url/#/FAQ#anchor-name

For anyone who might be interested, I fixed this issue. The problem was fixed by replacing HashHistory with BrowserHistory. With HashHistory, the URL gets an # that interferes with anchors. By using BrowserHistory, that # is never there so the issue is gone. Hopes this helps.

Related

i want to create dynamic sidebar in mern stack which render another component when they clicked

for your understanding i attached w3school screenshot.
enter image description here
if u have ever visited w3school website u will understand my requirement easily.
i want to create these html sidebar dynamic from my admin dashboard. first i will create one sidebar title name then insert content according to title name and so on..... for best understanding you can assume that i want to create w3school clone dynamic from where i can dynamic create sidebar and content. i read about react router dom and many more but not able to create like this.
You can use react-router for navigation and then render according to the route
https://codesandbox.io/s/c2zs4
here is the example I found, it used react-router for navigation and render components according to the route.
add in _app.js file
you can put a header here
<div className="flex">
<div className="W-2/6>
<Sidebar/>
</div>
<div className="w-4/6">
page component here
</div>
</div>
and footer here
I used tailwind CSS

How to render elasticsearch json info as clickable links with Vue.js

Hey there folks :) I am trying to set up a search engine with elasticsearch/node.js, express and vue.js. I would like the search results to be clickable links, but they are only returning non-clickable html. I have tried adding normal html A- tags to the .json file, but on the front end this renders as a non clickable html text and not as a clickable link. Any suggestions would be really appreciated
this is what I have tried, just as a test:
Visit our HTML tutorial
I have had a look on google for possible solutions but all I could find were references to the normal html a-tag and that both j.son and vue.js can take those?
If I correctly get the issue, At FE your link get rendered as sting which is Google . You need to use v-html in this case to tell element to render the passed value as html not as string
//Suppose you have this vue data prop
let url = Google
Now In you html part Just use v-html to render
<div class="foo">
<template v-html="url" />
</div>

Internal href of <a tag now refreshes the page

I've got several anchor tags pointing to internal links mainly to scroll to some section titles or to get to the top from a bottom link of the site since some pages can get very long.
All tags like Whatever just scrolled the page to the <a name="whatever"></a> tag as intended until yesterday, but now when clicked they force a page refresh pointing to the root page with just hash, like this localhost/#whatever instead of this localhost/path/to/current/page/#whatever.
1) Is there even the possibility to alter something in the Apache server, browser settings (not touched tough), HTML/JavaScript/CSS code of a page or whatever to force page refreshes when clicking on internal links?
2) If I change the anchor to <a href="path/to/current/page/#whatever> it works, but it's just because a page refresh triggers and then the page is scrolled like normal when interpreting the hash fragment. Also, this way I loose any GET parameters (I can't predict them) which I really need since it's a database website
3) If I alter or remove the <base href="/" /> tag nothing happens, still the internal links worked before with that tag in place
4) I recently updated the .htaccess file and that could potentially be the cause but still routing has no problems and I can't see why any RewriteRule could possibly affect internal links. Also, trying to revert it to previous version didn't help
5) Same behavior applies to both Firefox and Chrome, latest versions
6) I tried to create a test page in the same environment (same .htaccess, same HTML base template) with just a very long <ul> list containing list elements with integers in sequence until 500, then a To 20 at the bottom of the page and it just worked all good... What can force a internal link to redirect?! Please help
I finally solved it! Check here link and here link. The problem was with the <base href="/" /> tag in the <head> section. I solved with a mixture of jQuery and pure JavaScript (jQuery is used only for select anchors and get attribute), here
$("a.local").on("click", function (e) {
e.preventDefault();
document.location.hash = "";
document.location.hash = $(this).attr("href");
});
Please note that I need to set the hash to an empty string before actually setting it to the href of the anchor since document.location.hash = $(this).attr("href"); alone would not trigger automatic scrolling on multiple clicks on the internal anchor (I tried it)

How to add a post image in Ghost's index?

I don't see any examples in the docs on how to use a post's image on the index view of Ghost. For example, you can see this theme doing it: http://studio-lite-theme.ghostify.io/
Any ideas?
EDIT: If anyone comes across this, I found this post that helped: https://ghost.org/forum/themes/1401-tip-how-to-show-the-pic-of-your-post-in-index-hbs/
Since version 0.5.2 there's now official support for Post Images. So avoid the hack using {{content words="0"}}
Instead use {{image}} to print out the url for the image.
For example:
<header {{#if image}}" style="background-image: url({{image}}){{/if}}">
As #user3088077 mentioned in his edit, I could make the image appear in the index page by replacing in the index.hbs
from {{ excerpt }} to {{content words="0"}}.
What happens is that excerpt does not include images, while content does.
This is aimed towards displaying the featured image in index which means it needs to be on the front page not on post page.

How to click on link element with specific text using watir?

I'm not able to click on text link 'Add' using watir:
PAGE:
<div id="divAdd" style="float: right">
<a onclick="SwitchView('2')" style="color: #1B56A7; cursor: pointer;">Add</a>
</div>
Watir CODE:
browser.link(:text =>"Add").click
EXCEPTION:
Unable to locate element, using {:tag_name=>["a"], :text=>"Add"}
Please help me how to handle this?
If the page has a lot of ajax and javascript going on, you may just have to wait a little bit for the client side code to finish rendering the page after it has been loaded from the browser.
Try this
browser.link(:text =>"Add").when_present.click
If that does not work, then make sure the item is not in a frame or something..
btw, if there is more than one link on the page with the text 'Add' then you may have to specify a container outside the link that lets you identify which link you want. eg.
browser.div(id: => "divAdd").link.when_present.click
If
This would be my way of doing it.
while browser.div(:class, 'containerDIV').a(:text, 'Add').exists? do
browser.div(:class, 'containerDIV').a(:text, 'Add').click
end

Resources