Comments (12)
@brunorentcars please create a separate issue for this and I'll get on to it asap. Thanks!
from localize-router.
@dahfazz
Short answer: - you need to prefix base routes with backslash
['/users' | localize]
Long answer:
Router (and it's directives) work in a fashion that even if you skip providing the backslash (sign that it's a base route) if your link is defined on top level component (component without it's own routes) it will not consider it a relative sub route. However, localize-router
doesn't have deep knowledge/access to full routing mechanism, thus cannot distinguish this. The only way for localize-router
to know which route is base one (to preprend url with language) is by reading backslash as a first character in the url.
from localize-router.
Hi @Masquer, it might be that documentation is a bit misleading. Thanks for pointing that out. Documentation only explains the algorithm by which language gets chosen.
Localize-router prepends all the routes with selected language and creates a redirect to base language url e.g. my/route/path
will become en/my/route/path
. Once localize-router had been initialized it overrides the initial routes, so route my/route/path
no longer exists in RouterConfig and Router therefore returns 404. This is not defect, it's by design as above mentioned route is invalid.
There are two approaches to solve your request:
- By catching 404 and redirecting to {localize.parser.currentLang}/{location.path} manually in project
- By handling this in localize-router
Please note that at the moment this has low prio against lazy loading, and most likely will not be implemented any time soon.
from localize-router.
how can I add catching exception in router?
from localize-router.
@brunorentcars If you refer to catching 404 you can do it by pointing all unknown routes (**) to the component that will handle the redirection.
https://angular.io/docs/ts/latest/guide/router.html
If this is not what you're referring to, then please provide more information.
from localize-router.
if I set a different language on URI there isn't on configuration file(locales.json) my application crashes.
There routers for 404:
{path: '404', component: NotFoundComponent},
{path: '**', redirectTo: '404'}
But localize-router put this routers inside children language route.
For example:
{path: '', redirectTo: 'en', pathMatch: 'full'}
{path: 'en', children: [
{path: '404', component: NotFoundComponent},
{path: '**', redirectTo: '404'}
]}
from localize-router.
hello @brunorentcars just wondering if you managed to accomplish this behavior? Thnx
from localize-router.
@juanmcampos check this issue: #22
from localize-router.
@brunorentcars great! thnx I updated my module version, and was able to get that '**' wilcard route. But any clue on how do I get the requested url? so i can handle the translate? any help would be awesome really thnx
from localize-router.
@juanmcampos if you want to get the current route path, you can use ActivatedRoute.
For example:
constructor(private activatedRoute:ActivatedRoute) {
console.log(this.activatedRoute.snapshot.url)
}
If you want to get the full uri, you can use Router.
For example:
constructor(private router:Router) {
console.log(this.router.url)
}
from localize-router.
Hi @meeroslav
I'm dealing with a similar issue; On load everything is OK.
I'm on ***/en/home
There, I click on a link on which i put [routerLink]=['users' | localize]
It throws an error because /users doesn't exist anymore, and I should target /en/users
I thought it was exactly why I need to use localize Pipe.
What am I missing please ?
from localize-router.
Closing as this will not be implemented.
from localize-router.
Related Issues (20)
- localize-router not working as expected with Angular Universal: server-side rendering HOT 6
- Function traverseSnapshot not properly assembling the new translated route. HOT 11
- Localize router unable to pass data params on an empty path HOT 2
- Out of sync localize pipe HOT 1
- changeLanguage does not work for route with parameters HOT 6
- After language is switch, back button redirect into 404
- InitialNavigation enabled crashes Routing HOT 7
- Lazy loaded component is not bootstrapping HOT 4
- can't trigger window.load
- Angular 8 + IVy support HOT 1
- Can't make it, need tutorial. HOT 1
- Angular recognize only the default lang in SSR. HOT 4
- Angular 8 support HOT 6
- Extra slash translating root route
- LazyLoad Child Componenter onPage Refresh re-directs:Home Page HOT 1
- Unhandled promise rejection HOT 6
- Custom Cookies expiration
- Children routes issue lazy load module HOT 5
- Problem with Initial Navigation in RouterModule HOT 4
- LocalizeRouterModule.forRoot returns a ModuleWithProviders type without a generic type argument HOT 20
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from localize-router.