-
Notifications
You must be signed in to change notification settings - Fork 65
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
Getting cross links from the Wordpress installation #59
Comments
Yeah, so the trouble is that it's dynamic content. could be a external URL, could be a relative path, could be full path of the current site. When I worked with WordPress/Nuxt, I solved this by creating my own global component. You could call it "WuxtLink". Inside is the logic to check the URL:
Hope that helps. |
When the json response contains the slug you could do following: <nuxt-link v-for="menu in menus" :key="menu.id" :to="'/pathto' + menu.slug" >
{{ menu.title }}
</nuxt-link> |
slug was also what about I was thinking, but the json unfortunately doesn't contain the slug entry
|
A slug wouldn't be reliable anyway - think about nested pages for example, or if a custom URL is entered. |
Another suggestion: <vue-link v-for="menu in menus" :key="menu.id" :to="'menu.url.replace('http://localhost:3080','')">
{{ menu.title }}
</vue-link> Using this component: https://github.com/Developmint/vue-link |
Interesting, I guess what I had was kind of like My strategy was to use nuxtServerInit to get the host and protocol dynamically, for portability. async nuxtServerInit({ commit }, args) {
if (process.server) {
commit('SET_HOST_AND_PROTOCOL', {
host: args.req.headers.host,
protocol: args.req.headers['x-forwarded-proto']
});
}
} and in the link component /**
* Fix absolute URLs which really should have been relative
* Example: "http://myproject.localhost/about-us" -> "/about-us"
*/
const indexOfHost = url.indexOf('//' + context.parent.$store.state.host);
if (indexOfHost !== -1) {
url = url.substring(indexOfHost + 2 + context.parent.$store.state.host.length);
} |
Sorry, had no luck with them :-( |
OK, I found a workaround, making a const hostAdress (also adding it to the data() output) and then replacing it in the link |
That's a relevant feature request and something we working on! It's related with getting page and post previews right, hope we come with an update soon. |
Thanks! There is space for improvements, but otherwise it is a great project, has nice perspectives for usage. |
I very slightly modified Vue Link in order to produce a WpLink component that will strip off the WP URL (process.env.WUXT_WP_URL) for a link that was given to it, and use NuxtLink as the tag. You can also use the WpLinkToApi component which won't longer strip off the Api host, in case you want to link through to images that are hosted by WordPress, for example. https://gist.github.com/Jamiewarb/7787f36e1a3ed7636817e87314693487 |
I have a difficulty to make the nav menu work with the fetched json data and nuxt-link (but possibly this is a question for building the navigation for the whole site)
My problem is that the links that are fetched from the wp json are different domain, and hence the nux-link appends it to the a href. Or am I doing something wrongly?
The code:
On the output I get
Thank you in advance and big thanks for making this framework! (a bit of Wiki/FAQ would be very-very nice though ;-) )
The text was updated successfully, but these errors were encountered: