0

Angular was loading page on default port localhost:4200 i wanted it to serve as localhost:4200/specialtyquestions when app build and that is working but its showing pages twice in the browser , Any idea what is implemented wrong here ?

app-routing.module.ts

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


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


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

app.component.html

<app-navbar></app-navbar>
<div class="container-fluid">
    <div class="row">
        <div class="col-sm-5">
            <app-create-questions></app-create-questions>
        </div>
        <div class="col-sm-1">
            <div class="row">
                <button type="button" class="btn btn-primary" data-backdrop='static' (click)="openModal()" style="margin-top: 300px;" data-toggle="modal" data-target="#exampleModalLong">Start Formatting</button>
            </div>
        </div>
        <div class="col-sm-5">
            <app-format-questions></app-format-questions>
        </div>
    </div>
</div>
<h2>
    <router-outlet></router-outlet>
</h2>

image

enter image description here

4
  • Can you paste the html also? Commented Apr 9, 2020 at 17:20
  • @GouravGarg added html Commented Apr 9, 2020 at 17:25
  • i guess i have to remove router-outlet in this case ? Commented Apr 9, 2020 at 17:28
  • Yes you should, you don't need that. Commented Apr 9, 2020 at 17:29

1 Answer 1

1

Remove Router-Outlet because when you Add that tag at the last it Run that part again. so remove that part from the end and Check

<app-navbar></app-navbar>
<div class="container-fluid">
    <div class="row">
        <div class="col-sm-5">
            <app-create-questions></app-create-questions>
        </div>
        <div class="col-sm-1">
            <div class="row">
                <button type="button" class="btn btn-primary" data-backdrop='static' (click)="openModal()" style="margin-top: 300px;" data-toggle="modal" data-target="#exampleModalLong">Start Formatting</button>
            </div>
        </div>
        <div class="col-sm-5">
            <app-format-questions></app-format-questions>
        </div>
    </div>
</div>

Router part is needed when you want to route from one page to another e.x. 127.0.0.1:4000/Student

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

2 Comments

if i add more pages which will have different route then i would need to add router outlet back in app.component.html and it will show appComponent pages twice again no ?
Then you have to modify your little bit of code the things which is prefix that only you can hold on app.component.ts and for other thing you can make another component

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.