Skip to content
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

Issue with dynamic routes #3

Closed
jesperlandberg opened this issue May 22, 2018 · 14 comments
Closed

Issue with dynamic routes #3

jesperlandberg opened this issue May 22, 2018 · 14 comments
Assignees
Labels
bug Something isn't working

Comments

@jesperlandberg
Copy link

jesperlandberg commented May 22, 2018

Hi,

Thanks for this barba alternative=)

Currently testing it out but I'm having one issue. Links to Dynamic pages (Wordpress single pages) doesn't work properly. It works the first click/entry after a page refresh, but going between pages and then trying to enter a dynamic route causes a hard refresh. Any idea why?

JS

import '../css/app.scss'

import Highway from '@dogstudio/highway'

// Renderers
import Home from './home'
import Location from './location'

(() => {
	const links = [...document.querySelectorAll('.js-site-head__menu-link')]

	const H = new Highway.Core({
		renderers: {
			home: Home,
			location: Location
		},
		transitions: {

		}
	})

	H.on('NAVIGATE_IN', (from, state) => {
		for (const link of links) {
		  link.classList.remove('is-active')

		  if (link.href === state.url) {
		    link.classList.add('is-active')
		  }
		}
	})
})();

Single renderer:

import Highway from '@dogstudio/highway'
import Smooth from '../scroll'

let smooth

class Location extends Highway.Renderer {
	onEnter() {
		smooth = new Smooth()

		smooth.init()
	}
	onLeave() {
		smooth.destroy()
	}
	onEnterCompleted() { }
	onLeaveCompleted() { }
}

export default Location

Single page file (twig templating)

{% extends "base.twig" %}
{% block content %}
<article router-view="location" class="o-scroll js-scroll">
	<div class="o-scroll__content js-scroll__content">

	</div>
</article>
{% endblock %}

@Anthodpnt
Copy link
Contributor

Anthodpnt commented May 23, 2018

@jesperlandberg

I'm not sure to understand.
When you click a link to a single page from Wordpress the window reload happens ?
Do you have any error in the console ?

From what I see in your code you don't have any transition provided to Highway.
This could lead to some sort of hard refresh.

If you don't see the window reloading on click on your links but only the URL being updated this means Highway does his job and you might just need to provide a default transition for your pages. Otherwise I'll need more information (logs, errors,...) in order to help you.

Thanks,
Anthodpnt

@Anthodpnt
Copy link
Contributor

@jesperlandberg Do you have the router-wrapper as well in you HTML ?

@jesperlandberg
Copy link
Author

jesperlandberg commented May 24, 2018

@Anthodpnt the issue is with pages that have dynamic slugs, /:id for example. All pre defined pages works fine, but dynamic ones like blog posts and such seem to have issues.

The issue for me (and a friend @westwho is also trying out highway) seem to be that the second time we click a link to a blog post or dynamic page, a hard load of the pages happen.

"loads the site" -> clicks and enter blog post (works fine) -> goes back to home page -> clicks any blog post again (this time causing a hard load).

There are no errors show in the console or other logs.

I will try put it up on a test server for you to see later today.

Here is a little video showcasing the issue:
highway.zip

@deJong
Copy link
Contributor

deJong commented May 24, 2018

In addition to @jesperlandberg, there is always a hard refresh of the page once a link is loaded dynamically in the router view and clicked.

The transition works, but after about 100ms there is still a hard refresh.

Simple example:

<body>
   <main router-wrapper>
      <article router-view>

        <ul class='nav'>
         <li>
          <a href='#'>link</a> <!-- works when page is loaded normally but not when loaded by router view --!>
         <li>
        </ul>

      </article>
  </main>
</body>

@Anthodpnt
Copy link
Contributor

@jesperlandberg @deJong,

Thanks for your feedback!
I'll run some tests on my side and come back to you ASAP with a fix.

@jesperlandberg
Copy link
Author

@deJong yeah, exactly the problem I tried to explain haha, you did it better=)

@Anthodpnt
Copy link
Contributor

@jesperlandberg @deJong

Ok I see, should be an issue with event binding.
Will check it and come back to you.

Thanks again !

@Anthodpnt
Copy link
Contributor

@jesperlandberg @deJong

Should be fixed in v1.3.4.
The binding of the click event on links was triggered too soon...

Can you please update your package and tell me if this solves your issue please ?

Thanks a lot,
Anthodpnt

@jesperlandberg
Copy link
Author

@Anthodpnt I'm afraid the issue still remains for me=/

@Anthodpnt
Copy link
Contributor

@jesperlandberg

Did you update your package.json and node_modules, and rebuild your scripts ?
Links in router-view shouldn't trigger a hard refresh anymore...

The problem came from these lines:

// Now we show our content!
await this.To.show();

// Bind events
this.bind();

The bind method in charge of handling the click event on links in the router-view was called before the show method of the new page's renderer was called so basically the links were not collected and the click event wasn't bound properly.

I updated the basic-setup example top make sure it was working by adding links in the router-view elements and it solved the issue explained by @deJong that is apparently the same as yours...

Anthodpnt

@jesperlandberg
Copy link
Author

@Anthodpnt My mistake. I ran a command to update my package.json, which displayed 1.3.3 -> 1.3.4 ... but now I saw it didn't actually update my package file for some reason.

However, it seems to work fine now=) Thanks for the quick update!

@Anthodpnt
Copy link
Contributor

Ok perfect !
I'll wait for @deJong news before closing this issue.

Thank you for your helpful feedback!
Anthodpnt

@deJong
Copy link
Contributor

deJong commented May 25, 2018

Works like a charm @Anthodpnt 🔥. Thanks for the quick solution.

@Anthodpnt
Copy link
Contributor

@deJong @jesperlandberg

Ok perfect! I'll close the issue then.
Don't hesitate to share Highway.

Anthodpnt

@Anthodpnt Anthodpnt self-assigned this Jun 9, 2018
@Anthodpnt Anthodpnt added the bug Something isn't working label Jun 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants