Dheeraj Agrawal Dheeraj Agrawal - 5 months ago 28
AngularJS Question

Setting route in angular 2

I am trying to set a route so that if I hit

http://localhost:8080/user/beta/
, it redirects to
http://localhost:8080/user/beta/#spreadsheet
,
and shows the spreadsheet view, but my code is redirecting to:
http://localhost:8080/#spreadsheet
.

import { provideRouter, RouterConfig } from '@angular/router';

import {Spreadsheet} from './components/spreadsheet/spreadsheet.component';

const routes: RouterConfig = [
{ path: '', redirectTo: 'spreadsheet', terminal: true },
{ path: 'spreadsheet', component: Spreadsheet }
];

export const APP_ROUTER_PROVIDERS = [
provideRouter(routes)
];

Answer

Use HashLocationStrategy with <base href="/user/beta"> to define what part of the URL is static.