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.

Navigation to dynamic routes does not work properly

See original GitHub issue

I’m submitting a bug report

  • Library Version: 1.3.0

Please tell us about your environment:

  • Operating System: Windows [10]

  • Node Version: 8.11.2

  • NPM Version: 6.9.0
  • Aurelia CLI OR JSPM OR Webpack AND Version CLI 1.0.0-beta.7
  • Browser: Chrome

  • Language: ESNext

Current behavior: Documentation states that it is possible to configure moduleId using navigationStrategy function. But framework does not respect changes of instruction.config.moduleId when navigationStrategy function is called second time.

Expected/desired behavior: Framework should watch moduleId changes after navigationStrategy function is called.

I am trying to display different module when key parameter is present in a query string. http://example.com/ - should display ‘landing’ module, but http://example.com/?key=12345 should display ‘search’ module Here is my router config:

export class App {
  configureRouter(config, router) {
    const homeStratagy = (instruction) => {
      if (instruction.queryParams.key) {
      	instruction.config.moduleId = 'search';
      } else {
      	instruction.config.moduleId = 'landing';
      }
  	  console.log('homeStratagy:', instruction);
    };

    config.map([
      {route: '', name: 'home', navigationStrategy: homeStratagy}
    ]);

    this.router = router;
  }
}

Here is gist illustrating the problem: https://gist.run/?id=11d2f6926dc18f19fd9f7dd9f910bbcf If I run the above sample locally (not using gist) - I can see that line this.router.navigateToRoute('home', {key: Math.random()}); changes the browser URL, but does not reload current module. If I open this new url in a new tab - I will see the correct seach module.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:7 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
euglvcommented, May 22, 2019

@bigopon Adding determineActivationStrategy does not solve the problem.

But I have solved the issue by changing navigationStrategy function implementation:

    const homeStratagy = (instruction) => {
      if (instruction.queryParams.key) {
      	instruction.config.moduleId = 'search';
      } else {
      	instruction.config.moduleId = 'landing';
      }
      // These lines fixed the issue:
      if (instruction.config.viewPorts)
        instruction.config.viewPorts.default.moduleId = instruction.config.moduleId;
      console.log('homeStratagy:', instruction);
    };

Here is updated gist with working sample: https://gist.run/?id=4fde41f2bba1c2fd1914e09baad02a08

When navigationStrategy function is called for the first time - instruction.config.viewPorts is null, but when it is called for the second time - instruction.config.viewPorts.default.moduleId is filled with previous moduleId.

0reactions
euglvcommented, May 29, 2019

@davismj Hi, thank you for help. I already found the solution:

inside navigationStrategy function I should configure moduleId in two places: instruction.config.moduleId and instruction.config.viewPorts.default.moduleId

Read more comments on GitHub >

github_iconTop Results From Across the Web

Dynamic routing is not working while adding a new post
You first need to add or generate an id property, and then navigate to the correct path. If you are want to navigate...
Read more >
A Complete Guide to Routing in React
In this guide, we will learn how to perform routing in React using ... such as dynamic routing, programmatic navigation, no matching route, ......
Read more >
Limitations
React Navigation does not currently provide an easy way to do this. React Navigation currently works best in situations where your routes can...
Read more >
Router tutorial: tour of heroes
Verify that your new application runs as expected by running the ng serve command ... A wildcard route can navigate to a custom...
Read more >
How to Handle Routing in a React Application using the ...
It should work as expected. Nested and Dynamic Routing. At the moment, if you navigate to the /about page, the About component gets ......
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