3

I have only one route in my application so when application starts i want to show route as http://localhost:4200/specialtyQ for some reason now application is not loading i have below code to achieve that , How i can show correct url ?

app-routing.module.ts

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AppComponent } from './app.component';


const routes: Routes = [{
  path: '/specialtyQs',
  component: AppComponent
}];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

2 Answers 2

3

You need to add one default route to redirect

const routes: Routes = [{
   path: 'specialtyQs',
   component: AppComponent
 },
 {
   path: '',
   redirectTo: 'specialtyQs',
   pathMatch: 'full'
 }];

This will redirect to specific url.

Sign up to request clarification or add additional context in comments.

4 Comments

Worked Thank you Sir!
actually just noticed page is showing twice in the browser including navbar
you mean double content? can you add a screenshot?
asked new questions and added image there stackoverflow.com/questions/61126591/…
0

Just add a routing path like below in your code instead of the way you have added it.

import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
import { AppComponent } from './app.component';


const routes: Routes = [{
  path: '',
  redirectTo: '/specialtyQs',
  pathMatch: 'full'
}];

@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule]
})
export class AppRoutingModule { }

2 Comments

this is not changing anything url is still http://localhost:4200/ it should change to http://localhost:4200/specialtyQs and we did not specified component as i wanted to load appComponent as default
let me create a stackblitz instance for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.