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

Link to a dynamic route page doesn't work #48

Open
christian-schab opened this issue Nov 13, 2020 · 1 comment
Open

Link to a dynamic route page doesn't work #48

christian-schab opened this issue Nov 13, 2020 · 1 comment
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@christian-schab
Copy link
Contributor

Issue descriptions

Clicking on a link to a dynamic route page does not load the page. The DOM is not modified at all.
The console shows a 404 error for loading a js file containing the full slug.
e.g. /posts/post-1234.js 404 (Not Found)

Steps to reproduce the issue

  1. wrangler generate my-project https://github.com/flareact/flareact-template
  2. change flareact version in package.json to a current version e.g. "0.8.0-canary.2"
  3. Set a account_id in wrangler.toml
  4. Add a file "/pages/posts/[slug].js" like
import Link from "flareact/link";

export async function getStaticProps({ params }) {
    const { slug } = params;
    return {
        props: {
            slug,
        },
        // Revalidate every 8 hours
        revalidate: 60 * 60 * 8,
    };
}

export default function Post({ slug }) {
    return (
        <div className="container">
            <h1>Slug: {slug}</h1>
            <p>
                <Link href="/">
                    <a>Home</a>
                </Link>
            </p>
        </div>
    );
}
  1. Change index.js to contain link to dynamic route pages, e.g.:
import Link from "flareact/link";

export default function Index() {
  return (
    <div>
          <h1>
              You're running React on the Edge!
          </h1>
        <p>
            <Link href="/posts/test-1"><a>Test 1</a></Link><br/>
            <Link href="/posts/test-2"><a>Test 2</a></Link><br/>
            <Link href="/posts/test-3"><a>Test 3</a></Link><br/>
            <Link href="/posts/test-4"><a>Test 4</a></Link><br/>

        </p>
    </div>
  );
}
  1. npm install
  2. npm run dev
  3. Open Browser for http://127.0.0.1:8787
  4. Click on one of the links

What's the expected result?

I expect to see the requests page content.

What's the actual result?

The document body doesn't change at all.
The browser console shows a 404 error for a js file

Screen Recording

@jplhomer
Copy link
Member

Hi @christian-schab thanks for the bug report. This is actually the expected behavior right now, as you aren't providing an as parameter: https://flareact.com/docs/flareact-link#dynamic-routes

I realized this is out of sync with what is in the with-cms-wordpress example 🙈 I've updated it.

I do think we could do a better job of either:

  • Performing a "hard" page navigation if the route can't be found
  • Displaying a console error when router can't load the page
  • Infer the dynamic route on the client without requiring an as parameter, like Next.js recently shipped

@jplhomer jplhomer added enhancement New feature or request help wanted Extra attention is needed labels Nov 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants