Unable to access specific route in Angular if default route contains a parameter

Here is a list of my routes:

const routes: Routes = [
  {
    path: '',
    component: BlogLayoutComponent,
    children: [
      {
        path: ':pageNumber',
        component: HomeComponent
      },
      {
        path: '',
        component: HomeComponent
      },
      {
        path: 'article/:id',
        component: ArticleComponent
      },
      {
        path: 'articles-by-hashtag/:id',
        component: ArticlesByHashComponent
      },
      {
        path: 'articles-by-category/:id',
        component: ArticlesByCatComponent
      },
      {
        path: 'about-me',
        component: AboutMeComponent
      }
    ]
  }
];

All of the routes are functioning correctly, except for navigating to the about-me page using the routerLink:

<li><a [routerLink]="[ 'about-me' ]">ABOUT ME</a></li>

When attempting to navigate to the about-me route, it redirects to the default route if the default parameter :pageNumber is present. How can I resolve this issue without resorting to using router.navigate(...? I prefer not to use that method.

Answer №1

To modify your route, follow these steps:

<li><a [routerLink]="['/about-me']">ABOUT ME</a></li>

Next, make sure to include a route before the pageNumber parameter. It appears that your route definition for HomeComponent may not be accurate.

{
   path: 'something/:pageNumber',
   component: HomeComponent
},

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to execute the identical promise once more based on the outcome of the previous execution?

My dilemma involves a block of code enclosed within a promise. This particular code is responsible for modifying records in a remote database and reporting the number of records edited. In case the count of edited records exceeds 0 (indicating work done), ...

Determining when all promises have either been rejected or resolved using vanilla JavaScript promises

In an effort to transition to loading all resources in my web application asynchronously using basic JS promises, I have implemented a ScriptLoader function. Below is the code snippet for the ScriptLoader used to load .js files: function ScriptLoader() { ...

When running grunt-bower, I am encountering an error stating that _.object is not a function

I am attempting to execute the grunt-bower task in order to copy all of my bower components. Encountered an error while running "bower:dev" (bower) task TypeError: _.object is not a function at Object.exports.getDests (/Users/wonoh/cocApp/node_modules/g ...

Tips for displaying only the components associated with the user's role in Angular

Greetings everyone! I have a dashboard that features a menu showcasing all the components. I am looking to implement a functionality where, if logged in with the admin role, all components should be displayed. On the other hand, if logged in with the respo ...

Is there a way to update a JSON key using the "onchange" function in React?

I'm facing an issue. I have a form with two inputs. The first input is for the key and the second input is for the value. I need to update the values in the states whenever there is a change in the input fields, but I'm unsure of how to accomplis ...

Troubleshooting: AngularJS not displaying $scope variables

I have a question that has already been answered, but the suggested solutions did not work for me. Everything seems to be fine, but the content within curly brackets is not displaying on screen. <div ng-controller="Hello"> <p>The I ...

Ways to modify the attribute of an element in an ImmutableList({}) nested within Immutable.Map({})

Is there a way to modify the property of an item within an ImmutableList({}) that is nested inside an Immutable.Map({})? This is my current setup: const initialState = Immutable.Map({ width: window.board.width, height: window.board.height, li ...

Incorporating the parent tag name within jQuery elements

I am working with an HTML file that consists of around 100 elements. Using jQuery in my JavaScript file, I have created a variable to store all elements present in the HTML document. Additionally, I have another variable specifically for text nodes withi ...

Jade Compilation with Gulp

Currently utilizing gulp-jade, I have encountered an error with a particular template: 557| 558| > 559| 560| .tabs-wrap(ng-show="eventExists"): .contain-center 561| 562| #room-tabs-contain.contain-disable.contain: .contain-center unexpec ...

Adding flair to a fresh element and then removing it upon its inception

I'm working with a JavaScript code that creates a new element when a button is clicked. I have a question about it. Here's the JavaScript code snippet: var comment = document.querySelector("#AddComment"); var req = new XMLHttpRequest(); if(comm ...

Automatically sorting data in JavaScript from PHP-generated JSON

When I receive JSON data from PHP and use it in JavaScript to populate a select box, the order is automatically sorted. This behavior should not occur. I am utilizing this JSON as the value for HTML select box options and I require the data to be in its o ...

Verify if the location is enabled in Ionic 3

I am attempting to achieve multiple tasks within my app. Firstly, I am aiming to retrieve the device's location. On Android, a prompt is displayed requesting permission for the app to access the device's location, which functions correctly. I am ...

Saving information in node.js

My latest project involves creating an address book app using HTML, CSS, and JavaScript. The company provided me with a zip file containing the necessary resources to implement the app using node.js. However, my knowledge of node.js is limited and I have ...

When using next.js, a warning may be encountered that states: "A value of NaN was received for the `children` attribute. To resolve this, ensure the value is cast as

I am currently tackling my first Next.js project and have created a file called myCart.js. Below is the code snippet: function orderCard(arr1) { //Code here... } let noRefresh; function makeGetRequest() { //Code here... } export default makeGetReques ...

Creating dynamic styles with Material-UI's useStyles

Attempting to implement the same logic using material-ui's useStyle feature <div className={'container ' + (state.unlocked ? 'containerUnlocked' : '')}> I thought it might look like this: <div className={`${clas ...

Tips for waiting for a function to finish executing in node.js (using a for loop)

Currently, the issue lies in the fact that the for loop instantly loops through everything. However, I want it to pause before looping because each time the loop runs, it inserts data into the database (which takes time). Therefore, I would like it to wait ...

I am encountering an issue with Wedriver.IO where screenshots of executions on a Remote Selenium Grid Hub are not being included in my Allure Reports

wdio.conf.ci.js: The following code snippet has been added. afterTest: function(test, context, { error, result, duration, passed, retries }) { if (passed){ browser.takeScreenshot(); } }, I expect to see a screenshot attachment in the bottom right corn ...

Transform HTML into PNG with Canvas2image, followed by the conversion of PNG into BMP

Is there a direct way to convert HTML to BMP? After searching online, it seems that there isn't a straightforward method. So, I decided to convert HTML to PNG using canvas JS and then use PHP to convert the file from PNG to BMP. I have a question abou ...

Using a form generated on the fly for submission

Recently, I created a dynamic form that consists of select options and input boxes. Upon submitting the form, I require all data from the selects and inputs to be stored in separate variables. The following is an excerpt from the code: HTML CODE : < ...

Assign the callback function to execute when the select element loses focus

Is there a way to trigger a function when the user clicks out of a select menu without selecting an option, even though I know about the onChange and onFocus event listeners associated with the select HTML element? ...