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

[Router] Pages in subdirectories are not rendered properly #4895

Closed
cannikin opened this issue Mar 23, 2022 · 3 comments · Fixed by #4948
Closed

[Router] Pages in subdirectories are not rendered properly #4895

cannikin opened this issue Mar 23, 2022 · 3 comments · Fixed by #4948
Assignees
Labels
bug/confirmed We have confirmed this is a bug topic/router-&-navigation

Comments

@cannikin
Copy link
Member

cannikin commented Mar 23, 2022

Possibly related to #4896

When a page is in a subdirectory:

web/src/pages/Jobs/JobsPage.js

When deployed to a production environment (Netlify, in this case, or yarn rw build && yarn rw serve), following a link to the page results in the proper render behavior:

image

However, going directly to the URL (clicking in the address bar and pressing Enter) does not:

image

Note that the Layout (header and footer) are rendered, just not the content of the page.

This behavior is not present when using yarn rw dev

@noire-munich found a workaround: have the page export a single, anonymous default function, rather than a named variable that's then exported after the fact:

// broken
const JobsPage = () => {
  // ...
} 
export default JobsPage

// works
export default function () {
  // ...
}

The way that doesn't work is the style that our page generators create.

Not sure if this is related, but pages that are in subdirectories are not auto-imported correctly into Routes.js and need to be imported manually:

import JobsPage from 'src/pages/Jobs/JobsPage'

Steps to Reproduce

The bug is fixed in the main branch, but if you checkout commit 531ce408 you can see it: https://github.com/redwoodjs/sprout

Locally run yarn rw build && yarn rw serve.

@cannikin cannikin added topic/router-&-navigation bug/confirmed We have confirmed this is a bug labels Mar 23, 2022
@cannikin cannikin changed the title Pages in subdirectories are not rendered properly [Router] Pages in subdirectories are not rendered properly Mar 23, 2022
@dac09 dac09 self-assigned this Mar 24, 2022
@jtoar jtoar moved this to In progress in Release Mar 24, 2022
@jtoar jtoar added this to Release Mar 24, 2022
@dac09
Copy link
Contributor

dac09 commented Mar 25, 2022

To confirm @cannikin or @noire-munich - the bug happens even when you add the explicit import of the Jobs page?

@cannikin
Copy link
Member Author

So for me I started with the explicit import and got the bug.

Then @noire-munich discovered that you could change the export in the pages to be export default function() and the bug would go away (while keeping the explicit import).

Then @realStandal discovered that if you just use the page name prefixed with the directory like JobsNewJobsPage then you can remove the explicit import and the bug goes away.

@dac09
Copy link
Contributor

dac09 commented Mar 28, 2022

Super helpful @cannikin - appreciate it! I think I've fixed the prerender one, which likely resolves this, but I will create a test case for it too if I can.

@jtoar jtoar moved this from In progress to Done in Release Apr 2, 2022
@jtoar jtoar moved this from Done to Archived in Release Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/confirmed We have confirmed this is a bug topic/router-&-navigation
Projects
No open projects
Status: Archived
Development

Successfully merging a pull request may close this issue.

3 participants