Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changeLanguage does not work for route with parameters #154

Open
azhararmar opened this issue Jan 14, 2019 · 6 comments
Open

changeLanguage does not work for route with parameters #154

azhararmar opened this issue Jan 14, 2019 · 6 comments

Comments

@azhararmar
Copy link

azhararmar commented Jan 14, 2019

I'm submitting a ... (check one with "x")

[*] bug report => Search github for a similar issue or PR before submitting
[ ] feature request => Please check if similar feature request does not exist
[ ] support request => Suggested place for help and support is [stackoverflow](https://stackoverflow.com/), search for similar question before posting

Description

When I try to use changeLang for route with parameters, it tries to construct invalid url resulting in the following error (however it works fine for route without any parameters)

Cannot match any routes. URL Segment: ar/venue%2Fmovenpick-hotel-kuwait-1;slug=movenpick-hotel-kuwait-1

I have following routes

export const routes: Routes = [
	{
		path: 'venue',
		component: HomeComponent
	},
	{
		path: 'about-us',
		component: AboutUsComponent
	},
	{
		path: 'search-result',
		component: SearchResultComponent
	},
	{
		path: 'venue/:slug',
		component: BusinessComponent,
	},
	{
		path: 'venue/:venue-slug/:meeting-room-slug',
		component: MeetingRoomComponent,
		children: [
			{
				path: 'description',
				component: BusinessDescriptionComponent
			},
			{
				path: 'terms',
				component: BusinessTermsComponent
			}
		]
	},
];

It throws mismatch route error for path venue/:slug and venue/:venue-slug/:meeting-room-slug but works fine for the rest of route.

What I understand from error is, for example for route venue/:slug with slug value movenpick-hotel-kuwait-1, it tries and construct the route ar/venue%2Fmovenpick-hotel-kuwait-1;slug=movenpick-hotel-kuwait-1 the extra parameter that is added here is ;slug=movenpick-hotel-kuwait-1 in the end. If it constructs just the ar/venue%2Fmovenpick-hotel-kuwait-1 it must work.

urlSegments in LocalizeRouterService.prototype.changeLanguage returns me following object

0: "/ar"
1: "venue/movenpick-hotel-kuwait-1"
2: {slug: "movenpick-hotel-kuwait-1"}

Problem is with the last element in the object, because URL already has slug value, it tries and add slug at the end as well resulting with the issue.

🌍 Your Environment

Angular Version:

Angular CLI: 7.1.4
Node: 11.2.0
OS: darwin x64
Angular: 7.1.4

Localize Router Version:
2.0.0-RC.1

@azhararmar
Copy link
Author

Issue related to #151

@macure
Copy link

macure commented Feb 11, 2019

Same issue here

@hohler
Copy link

hohler commented Feb 22, 2019

same issue here, downgrading Angular router did not help.
Solution from #151 is working for me!

@pixelatorz
Copy link

pixelatorz commented Jan 3, 2020

I found a solution, what I did previously is making routes like this and it resulted into errors when trying to change the language.
{ path: 'rewards', component: RewardOverviewComponent, }, { path: 'rewards/:id', component: RewardDetailComponent, },
however when you build your routes like this:

{ path: 'rewards', children: [ { path: '', component: RewardOverviewComponent }, { path: ':id', component: RewardDetailComponent } ] },

@ntopulos
Copy link

ntopulos commented Jan 15, 2020

Same issue here. The suggestion of children routes is unfortunately not suitable in all situations.

@LaithMuhaiesn
Copy link

instead of changelanguage try using this
window.location.href = this.router.url.replace(this.localize.parser.currentLang, lang);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants