digitalascetic / iron-router-i18n

Meteor iron router support for i18n
MIT License
36 stars 5 forks source link

Error: A route for the path "/en/pathInEnglish" already exists by the name of "myPage". #58

Closed mwarren2 closed 9 years ago

mwarren2 commented 9 years ago

I have an app I've been working on for about two months. I had a router.js with about thirty routes in it, all with /en and /it prefixes and it was working perfectly thanks to iron-router-i18n.

About a week ago I did a 'meteor update' and since then meteor just crashes at start up with the above message or similar. Since then I have been working continuously trying to work out what is wrong/correct the problem. I have reached dead end after dead end. The only way to stop the crash is to uninstall your package.

I have constructed a totally minimal router.js to illustrate the problem. I would be grateful if you would simply look at my minimal router.js and tell me what is wrong with it. Clearly there is no other route already existing with the same name.

=> Your application is crashing. Waiting for file change. => Modified -- restarting. W20150517-23:44:13.156(2)? (STDERR)
W20150517-23:44:13.157(2)? (STDERR) /Users/malcolm/.meteor/packages/meteor-tool/.1.1.3.1wysac9++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:245 W20150517-23:44:13.157(2)? (STDERR) throw(ex); W20150517-23:44:13.157(2)? (STDERR) ^ W20150517-23:44:13.177(2)? (STDERR) Error: A route for the path "/en/pathInEnglish" already exists by the name of "myPage". W20150517-23:44:13.177(2)? (STDERR) at Iron.utils.assert (packages/iron:core/lib/ironcore.js:10:1) W20150517-23:44:13.178(2)? (STDERR) at Function.Router.route (packages/iron:router/lib/router.js:137:1) W20150517-23:44:13.178(2)? (STDERR) at Function.Router.route (packages/martino:iron-router-i18n/lib/router.js:269:1) W20150517-23:44:13.178(2)? (STDERR) at app/lib/router.js:15:8 W20150517-23:44:13.178(2)? (STDERR) at app/lib/router.js:27:3 W20150517-23:44:13.178(2)? (STDERR) at /Users/malcolm/git/malcolm-warren/sagrona/.meteor/local/build/programs/server/boot.js:222:10 W20150517-23:44:13.178(2)? (STDERR) at Array.forEach (native) W20150517-23:44:13.178(2)? (STDERR) at Function..each._.forEach (/Users/malcolm/.meteor/packages/meteor-tool/.1.1.3.1wysac9++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11) W20150517-23:44:13.178(2)? (STDERR) at /Users/malcolm/git/malcolm-warren/sagrona/.meteor/local/build/programs/server/boot.js:117:5 => Exited with code: 8 => Your application is crashing. Waiting for file change.

Router.js

I18NConf.configure({

    defaultLanguage: 'en',

    languages: ['en', 'it'],

    autoConfLanguage: false

});

Router.configure({
    layoutTemplate: 'layout'
});

Router.route('/en/pathInEnglish', {
    name: 'myPage',
    i18n: {
        languages: {
            it: {
                path: '/it/pathInItalian'
            }
        }
    }

});
martinopic commented 9 years ago

It's a strange configuration as usually Iron Router i18n is used to automatically add the lang prefix ('en', 'it') to the route so . Did you just update meteor or also updated Iron Router i18n? Which version of Iron Router i18n were you using and which are you using now?

It should work anyway so I'll have a look asap.

mwarren2 commented 9 years ago

martino:iron-router-i18n@0.5.4 was the version before update martino:iron-router-i18n@1.0.1 is current version

iron-router stayed at 1.0.7

Yes I do have the lang prefixes, but they aren't essential to me. I tried without as well, but Meteor continued crashing, so after a couple of days of trying I'm assuming it wasn't me, and am turning to you in the hopes that you can find something.

Current versions file for what it's worth: accounts-base@1.2.0 accounts-password@1.1.1 alanning:roles@1.2.13 aldeed:autoform@5.1.2 aldeed:collection2@2.3.3 aldeed:simple-schema@1.3.3 amplify@1.0.0 anti:i18n@0.4.3 autoupdate@1.2.1 base64@1.0.3 binary-heap@1.0.3 blaze@2.1.2 blaze-tools@1.0.3 boilerplate-generator@1.0.3 callback-hook@1.0.3 check@1.0.5 coffeescript@1.0.6 ddp@1.1.0 deps@1.0.7 ejson@1.0.6 email@1.0.6 fastclick@1.0.3 fongandrew:find-and-modify@0.2.1 force-ssl@1.0.4 geojson-utils@1.0.3 html-tools@1.0.4 htmljs@1.0.4 http@1.1.0 ian:accounts-ui-bootstrap-3@1.2.56 id-map@1.0.3 iron:controller@1.0.7 iron:core@1.0.7 iron:dynamic-template@1.0.7 iron:layout@1.0.7 iron:location@1.0.7 iron:middleware-stack@1.0.7 iron:router@1.0.7 iron:url@1.0.7 jag:pince@0.0.6 jquery@1.11.3_2 json@1.0.3 launch-screen@1.0.2 less@1.0.14 livedata@1.0.13 localstorage@1.0.3 logging@1.0.7 martino:i18n-conf@0.3.1 martino:iron-router-i18n@1.0.1 meteor@1.1.6 meteor-platform@1.2.2 mike:mocha@0.5.4 minifiers@1.1.5 minimongo@1.0.8 mizzao:bootstrap-3@3.3.1_1 mobile-status-bar@1.0.3 momentjs:moment@2.9.0 mongo@1.1.0 mrgalaxy:stripe@2.1.0 mrt:cookies@0.3.0 mystor:device-detection@0.2.0 nblazer:casperjs@0.1.6 npm-bcrypt@0.7.8_2 numeral:numeral@1.5.3 observe-sequence@1.0.6 ongoworks:security@1.1.0 ordered-dict@1.0.3 package-version-parser@3.0.3 practicalmeteor:chai@1.9.2_3 practicalmeteor:loglevel@1.1.0_3 random@1.0.3 reactive-dict@1.1.0 reactive-var@1.0.5 reload@1.1.3 retry@1.0.3 routepolicy@1.0.5 rzymek:moment@2.8.3_10 rzymek:moment-locale-it@2.9.0 sacha:spin@2.0.4 sanjo:long-running-child-process@1.0.3 sanjo:meteor-files-helpers@1.1.0_4 sanjo:meteor-version@1.0.0 service-configuration@1.0.4 servicelocale:geoip@0.1.3 session@1.1.0 sha@1.0.3 spacebars@1.0.6 spacebars-compiler@1.0.6 srp@1.0.3 stylus@1.0.7 templating@1.1.1 tracker@1.0.7 u2622:persistent-session@0.3.5 ui@1.0.6 underscore@1.0.3 url@1.0.4 velocity:chokidar@0.12.6_1 velocity:core@0.6.1 velocity:html-reporter@0.5.3 velocity:meteor-internals@1.1.0_7 velocity:shim@0.1.0 webapp@1.2.0 webapp-hashing@1.0.3 webix:skin-flat@2.3.14 webix:webix@2.3.8_1

mwarren2 commented 9 years ago

I've tried my little example without prefixes and yes it works, so please don't waste time on this. I will go back to the main app and take a further look at this, and get back if necessary

martinopic commented 9 years ago

This is what I was thinking: what confuses Iron Router i18n are the prefix routes, neverthless it should work also with lang prefixed routes or at least give a warning so I'll keep this issue open even if it's a minor issue :-)

mwarren2 commented 9 years ago

Thank you for your help, it's all beginning to work again. I can't explain why I put the prefixes. I also had to change Router.getLanguage() to I18NConf.getLanguage() which I found in another issue. Thanks again.

mwarren2 commented 9 years ago

Ok, I now recall why I ended up adding the lang prefixes: it was because it was the only way I found to solve an apparently simple task, which is a little exception for the home page.

In english, and only in english, I need to leave off the lang prefix for the home page, thus on my test machine http://localhost will respond in english and my domain home page in production will respond nicely in the same way. http://localhost/it should continue to respond normally.

Should be easy: must be a combination of compulsoryLangCode: false with missingLangCodeAction or addLangCode (or maybe exclude). I tried every imaginable combination of these, but nothing wanted to work. FATAL ERROR!

I finally worked it out: I should have left compulsoryLangCode: true . Because missingLangCodeAction isn't even called if compulsoryLangCode is false. I suppose with hindsight that this is logical, but I spent an indecent amount of time, which I won't admit to anyone, solving this problem.

Now I am trying to get missingLangCodeAction to work, again without success. If you search the internet you will see that there is not a single example on the whole of the web, and I am stuck.

The path provided is actually a url string, so I first find the path without the host, then I'd like to see the page of course. But I just get the normal layout, header and footer, and the actually content doesn't show (if I return false). If I return true, I get a blank page. I would like to just say "Router.render('home')" I suppose, and return true but I don't have a reference to Router here. Here is my code:

   missingLangCodeAction: function(path){
        if(Meteor.isServer)
            return false;

        var doubleSlashIndex = path.indexOf('://');
        var firstPathSlash = path.indexOf('/', doubleSlashIndex + 3);
        var myPath = path.substring(firstPathSlash);

        if (myPath === '/') {
            console.log('found my path and responding', myPath);
            I18NConf.setLanguage('en');
            //Router.render('home');
            return true;
        }
         return false;
    }
martinopic commented 9 years ago

There is an option to avoid lang code for all default language routes which is langCodeForDefaultLanguage (default is true) but I guess you just want to avoid language code for the home page.

The router is available inside any configurable hook as "this", not sure whether rendering the template inside missingLangCodeAction would work.

A cleaner way to solve your problem could be to use exclude: true option for the home page default language route and manually add the other i18n paths/routes needed.

P.S.

As for the fact missingLangCodeAction is called just when compulsoryLangCode is true I will add this on documentation (it's just stated in compulsoryLangCode docs unfortunately).

mwarren2 commented 9 years ago

Ok, I shall drop my stupid idea to have just the home page without the prefix. Much better to go with the package defaults (I will use langCodeForDefaultLanguage = false) and have less of my own code to worry about.

Thank you so much for your time and help. I think this has solved everything.