question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inject Dynamic url parameter into template

See original GitHub issue

Describe the bug A clear and concise description of what the bug is. What i’m seeing is that with next v11 the following code works in a way where the id url parameter is injected into the template name:

  @Get('/:id')
  @Render('[id]') // if :id were '2' the template name would be [2]
 public post(@Param('id') id: string) {
    return {id};
  }

However with next v12 this doesn’t seem to work anymore. What i’ve observed with v12 is that ctx.query.id is set to the string [id] rather than the actual id value.

Expected behavior A clear and concise description of what you expected to happen.

I’d expect the behavior with next v11 to be the same as v12. I’m not sure if nest-next module should be bridging the gap but it would be neat for this to still work as it did.

To Reproduce

Repository URL:

Version

  • next.js: 12.1.1
  • nest: 8.0.0
  • nest-next: 9.6.0

Additional context Add any other context about the problem here.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
rushil-patelcommented, Mar 29, 2022

@kyle-mccarthy Yeah sure thing. Here is a demo repo. The master branch is working as expected with Next v11. I put a branch called next-12 where you can observe the broken behavior, following these steps: repo: https://github.com/rushil-patel/nest-next-test

// SETUP Clone nest-next-test repository and check out the next-12 branch

  • yarn

  • yarn build

  • yarn start

  • Navigate to http://localhost:3000/1 // you’ll see a 500 internal error

You’ll see in the stacktrace that the id url parameter is not 1 but ends up being [id].

To see it work with next 11 checkout the master branch and run the exact 4 steps above

0reactions
kyle-mccarthycommented, Apr 9, 2022

Hey, sorry, I just had the opportunity to look into this issue. I noticed that in your example, you used the monorepo approach; this was contributed by a member that has since deleted their GitHub account. Unfortunately, this was never a use case of mine, and I cannot provide any meaningful suggestions or workarounds.

That being said, the “basic” example still works as expected. The primary difference between the “basic” and “monorepo” example is that the monorepo attempts to bypass how Next treats the pages directory. Next is pretty opinionated in how they treat the pages directory, even when using the custom server approach.

It may be possible to get around the problem by symlinking the pages directory; however, this is obviously less than ideal. Given that the contributor can no longer provide support, I will start to remove the example and references to it in the documentation.

If you can get it working, I would appreciate it if you could let me know or make a PR with fixes for the documentation and examples.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Add parameter to url. Make url dynamic - Stack Overflow
I have a function and i am trying to ...
Read more >
How to Display Dynamic Content on a Page Using URL ...
In this tutorial, I will show you how to show/hide dynamic content based on URL parameters for any web page. This solution uses...
Read more >
AdSkills | Dynamic URL Parameters In Adwords (ValueTrack)
AdSkills ValueTrack Tracking Template : {lpurl}?utm_medium=cpc&utm_source=google&utm_campaign={campaignid}&utm_con AdSkills ValueTrack ...
Read more >
Using dynamic references to specify template values
Dynamic references provide a concise, powerful way for you to specify external values stored and managed in other services in your stack templates....
Read more >
Create URL templates for specific product groups, dynamic ...
Create and apply URL templates. Create URL templates for specific product groups, dynamic targets, and dynamic ads. Next: Use a bulksheet to create,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found